lwsjs / local-web-server

A lean, modular web server for rapid full-stack development.
MIT License
1.22k stars 86 forks source link

Server crashes on error #88

Closed bennypowers closed 6 years ago

bennypowers commented 6 years ago

When running lighthouse audits on my page served with lws, I consistently get server crashes a few minutes in to the audit

sudo npm start -- --port 443

> mws-restaurant-stage-1@1.0.0 start /Users/bennyp/Documents/mws-restaurant-stage-1
> npx ws "--port" "443"

Serving at https://iMac.local:443, https://127.0.0.1:443, https://10.0.0.13:443, https://10.211.55.2:443, https://10.37.129.2:443
 Clients  Requests  Transferred 
 1        1         2.19 KiB    

 Extension  Requests  Transferred 
 Clients  Requests  Transferred 
 1        55        369.52 KiB  

 Extension  Requests  Transferred 
 .html      28        311.58 KiB  
 .js        14        40.36 KiB   
 .css       10        13.19 KiB   
 <none>     2         4.37 KiB    
 .ico       1         9 B         

 Resource                                                              Requests  Transferred 
 200 GET /bower_components/polymer/lib/mixins/element-mixin.html       2         58.54 KiB   
 200 GET /                                                             2         4.37 KiB    
 200 GET /css/width-500.css                                            2         174 B       
 200 GET /css/width-630.css                                            2         442 B       
 200 GET /css/width-960.css                                            2         186 B       
 200 GET /bower_components/webcomponentsjs/webcomponents-loader.js     2         6.16 KiB    
 200 GET /bower_components/service-worker/service-worker.html          2         14.80 KiB   
 200 GET /js/main.js                                                   2         14.26 KiB   
 200 GET /css/width-1030.css                                           2         400 B       
 200 GET /js/dbhelper.js                                               2         3.76 KiB    
 200 GET /js/lib.js                                                    2         8.16 KiB    
 200 GET /bower_components/polymer/polymer-element.html                2         3.20 KiB    
 200 GET /js/maphelper.js                                              2         2.11 KiB    
 200 GET /bower_components/lazy-imports/lazy-imports-mixin.html        2         4.27 KiB    
 200 GET /js/idb-keyval.js                                             2         3.41 KiB    
 200 GET /bower_components/polymer/lib/utils/html-tag.html             2         9.38 KiB    
 200 GET /bower_components/polymer/lib/utils/import-href.html          2         7.51 KiB    
 200 GET /bower_components/lazy-imports/lazy-imports-import.html       2         6.96 KiB    
 200 GET /css/styles.css                                               2         12.02 KiB   
 200 GET /bower_components/polymer/lib/utils/case-map.html             1         1.88 KiB    
 200 GET /bower_components/polymer/lib/utils/settings.html             1         3.79 KiB    
/Users/bennyp/Documents/mws-restaurant-stage-1/node_modules/lws/lib/lws.js:237
    socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
          ^

TypeError: Cannot read property 'end' of undefined
    at Server.server.on (/Users/bennyp/Documents/mws-restaurant-stage-1/node_modules/lws/lib/lws.js:237:11)
    at emitOne (events.js:115:13)
    at Server.emit (events.js:210:7)
    at emitOne (events.js:120:20)
    at TLSSocket.emit (events.js:210:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mws-restaurant-stage-1@1.0.0 start: `npx ws "--port" "443"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the mws-restaurant-stage-1@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/bennyp/.npm/_logs/2018-03-04T20_43_46_771Z-debug.log

A little logging on that line (if (!socket) console.log(error)) shows that this was the error which precipitated the crash

{ Error: read ECONNRESET
    at _errnoException (util.js:1041:11)
    at TLSWrap.onread (net.js:606:25) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

FWIW here's the crash log from lighthouse

Initial URL: https://127.0.0.1/ Chrome Version: 64.0.3282.186 Error Message: Unable to load page: no document request found Stack Trace:

Error: Unable to load page: no document request found
    at Function.assertPageLoaded (chrome-devtools://devtools/remote/serve_file/@9611116ee79c63602f452e4fae2242a61cf0672d/audits2_worker/audits2_worker_module.js:826:73)
    at pass.then._ (chrome-devtools://devtools/remote/serve_file/@9611116ee79c63602f452e4fae2242a61cf0672d/audits2_worker/audits2_worker_module.js:830:224)
    at <anonymous>
75lb commented 6 years ago

is this on Windows? Are you running ws with any config, if so can you send me the content of your lws.config.js file?

75lb commented 6 years ago

i can't reproduce this, could you send me a failing test case? I've got a feeling this is a node bug, are you using node v9.4 or higher? socket should never be undefined in the clientError event handler.

bennypowers commented 6 years ago

I've got a consistent repro (Mac) with http://github.com/bennypowers/mws-restaurant-stage-1.git

git clone git@github.com:bennypowers/mws-restaurant-stage-1.git
npm i
npx bower i
npm start

run lighthouse in chrome audits panel.

Crashes afaict after "StartUrl" but I haven't found a more detailed crash log.

bennypowers commented 6 years ago

node -v v8.4.0

75lb commented 6 years ago

After changing server: 'http2' to server: 'lws-http2' in your config file I am able to reproduce this, looking into it now.

75lb commented 6 years ago

The error you saw (below) made sense as the browser had cancelled the request (ECONNRESET), killing the socket.

    socket.end('HTTP/1.1 400 Bad Request\r\n\r\n')
          ^

TypeError: Cannot read property 'end' of undefined

Fixed in lws v1.1.9 by testing the socket exists before writing to it. Please re-install local-web-server. Your lighthouse audit should run now.

75lb commented 6 years ago

just released lws v2.5.0 which now has the --http2 option for native HTTP2 support. See here. Let me know if you find any issues, thanks.

75lb commented 6 years ago

so, your config would change from server: 'lws-http2' to http2: true

bennypowers commented 6 years ago

This is really fantastic. THANK you for putting this together.

I noticed that when running npx ws with the following config, I do not get https, only http.

module.exports = {
  stack: [
    'lws-body-parser',
    'lws-request-monitor',
    'lws-log',
    'lws-compress',
    'lws-mock-response',
    'lws-static',
    'lws-cors',
  ],
  http2: true,
  mocks: 'restaurant-mocks.js',
  logFormat: 'stats',
};
75lb commented 6 years ago

have you updated your local dependencies? you've still got the old version installed, locally...

On 6 Mar 2018 17:29, "Benny Powers" notifications@github.com wrote:

This is really fantastic. THANK you for putting this together.

I noticed that when running npx ws with the following config, I do not get https, only http.

module.exports = { stack: [ 'lws-body-parser', 'lws-request-monitor', 'lws-log', 'lws-compress', 'lws-mock-response', 'lws-static', 'lws-cors', ], http2: true, mocks: 'restaurant-mocks.js', logFormat: 'stats', };

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/lwsjs/local-web-server/issues/88#issuecomment-370861384, or mute the thread https://github.com/notifications/unsubscribe-auth/ABMK7KRUoM8NElIPwUQUeC6ZNnfZQaOiks5tbsdzgaJpZM4SbfpF .

bennypowers commented 6 years ago

ok with the following package.json and the same config as above, I was off to the races. Thanks again!

{
  "name": "mws-restaurant-stage-1",
  "version": "1.0.0",
  "description": "Project files for MWS Nanodegree",
  "main": "index.html",
  "dependencies": {
    "express": "^4.16.2",
    "local-web-server": "^2.5.0",
    "lws-compress": "^0.2.1",
    "lws-http2": "^0.2.2",
    "node": "^8.9.4"
  },
  "devDependencies": {
    "bower": "^1.8.2",
    "eslint": "^4.18.2",
    "eslint-config-recommended": "^2.0.0",
    "eslint-plugin-html": "^4.0.1",
    "eslint-plugin-no-loops": "^0.3.0",
    "htmlhint": "^0.9.13",
    "stylelint": "^8.4.0"
  },
  "scripts": {
    "start": "npx ws & node server",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git@github.com:bennypowers:mws-restaurant-stage-1.git"
  },
  "author": "Benny Powers",
  "license": "ISC"
}

Do you have a donate link or a buy-me-a-beer button?