Page MenuHomePhabricator

Error when specifying a localhost URL for mobileapps.host
Closed, InvalidPublic

Description

While testing a mobileapps featured feed patch with an Android emulator, I discovered that RESTBase no longer seems to handle localhost URLs. This is true for either http://localhost:6927, localhost:6927, or http://0.0.0.0:6927.

Steps to reproduce

  1. Link or copy config.example.wikimedia.yaml to config.yaml
  2. Change default_project.x-modules[0].mobileapps.host from https://appservice.wmflabs.orgto http://localhost:6927

3a. In the app, change RESTBaseUriFormat dev setting to http://<host>:7231/%2$s/v1/ and refresh the feed
3b. Visit the following URLs in the browser:

Discussion

The following error is thrown for the /feed/announcment request:

{
  "type": "server_error#empty_response",
  "title": "HyperSwitch error: No content returned by backend.",
  "method": "get"
}

As seen in the log output, the underlying error is this:

{"name":"restbase",
"hostname":"wmf1256.local",
"pid":20718,
"level":50,
"root_req":{
  "method":"get",
  "uri":"/en.wikipedia.org/v1/feed/announcements",
  "headers":{
    "cache-control":"max-stale=0",
    "user-agent":"WikipediaApp/2.7.239-alpha-2018-08-21 (Android 8.1.0; Phone) Alpha Channel",
    "x-client-ip":"::ffff:127.0.0.1",
    "x-forwarded-for":"::ffff:127.0.0.1",
    "x-request-id":"8a3809b2-a55d-11e8-accd-9162e02bb1f9",
    "x-request-class":"internal"}
  },
"response":"TypeError: Cannot read property 'length' of undefined\n
    at HyperSwitch._request (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:200:45)\n
    at _createFilteredHandler (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:171:26)\n
    at tryCatcher (/Users/mholloway/code/wikimedia/restbase/node_modules/bluebird/js/release/util.js:16:23)\n
    at /Users/mholloway/code/wikimedia/restbase/node_modules/bluebird/js/release/method.js:15:34\n
    at handlerWrapper (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:398:37)\n
    at next (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:384:42)\n
    at Object.module.exports [as filter] (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/filters/http.js:24:16)\n
    at handlerWrapper (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:396:27)\n
    at /Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:402:28\n
    at HyperSwitch._filteredRequest (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:172:19)\n
    at HyperSwitch.request (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/hyperswitch.js:161:21)\n
    at Object.requestHandler (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/handlerTemplate.js:219:34)\n
    at handlers.push (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/handlerTemplate.js:268:29)\n
    at P.map (/Users/mholloway/code/wikimedia/restbase/node_modules/hyperswitch/lib/handlerTemplate.js:280:20)\n
    at tryCatcher (/Users/mholloway/code/wikimedia/restbase/node_modules/bluebird/js/release/util.js:16:23)\n
    at MappingPromiseArray._promiseFulfilled (/Users/mholloway/code/wikimedia/restbase/node_modules/bluebird/js/release/map.js:61:38)",
"msg":"No content returned",
"request_id":"8a3809b2-a55d-11e8-accd-9162e02bb1f9",
"levelPath":"error/request",
"time":"2018-08-21T16:16:21.090Z",
"v":0}

Also, the /feed/featured/yyyy/mm/dd request also returns an empty object, presumably because it (intentionally) swallows errors for the constituent individual mobileapps endpoint requests.

Drilling down a bit, it looks like in this instance, req.uri is a string rather than an object at the point the TypeError is being thrown (when it tries to get the length of req.uri.path).

Event Timeline

@Mholloway Would you add full URLs to what you are trying to do? From the headers it looks like you're using the Android app.

Thank you, @bearND, this was indeed a case of user error. I hadn't done this:

If using a localhost in any of the backend services (e.g. MCS) then make sure the patterns allow http, too, in addition to https. So, change the https patterns to https? in the config.yaml.

The error thrown could have been more directly related and informative, but anyway this can be declined for now.

Mentioned in SAL (#wikimedia-operations) [2018-08-22T09:49:43Z] <mobrovac@deploy1001> Started deploy [restbase/deploy@5d03f1c]: Expand CSS end points - T202425

Mentioned in SAL (#wikimedia-operations) [2018-08-22T09:53:08Z] <mobrovac@deploy1001> Finished deploy [restbase/deploy@5d03f1c]: Expand CSS end points - T202425 (duration: 03m 25s)

Oops, used the wrong ticket no for the deployment ^ :/