Skip to content

fix: handle a potential uncaughtException#113

Merged
shellscape merged 1 commit intoshellscape:masterfrom
niieani:patch-1
Feb 20, 2019
Merged

fix: handle a potential uncaughtException#113
shellscape merged 1 commit intoshellscape:masterfrom
niieani:patch-1

Conversation

@niieani
Copy link
Contributor

@niieani niieani commented Feb 18, 2019

This PR contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

If yes, please describe the breakage.

Please Describe Your Changes

Fixes a case in which we tried to send data through a socket that isn't connected due to the client being in the middle of a page reload (and thus closing the connection). This exception killed the whole webpack process.

Example stacktrace:

uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
    at WebSocket.send (/app/node_modules/ws/lib/websocket.js:322:19)
    at WebpackPluginServe.socket.progress (/app/node_modules/webpack-plugin-serve/lib/routes.js:87:16)
    at WebpackPluginServe.emit (events.js:189:13)
    at ProgressPlugin (/app/node_modules/webpack-plugin-serve/lib/index.js:212:16)
    at update (/app/node_modules/webpack/lib/ProgressPlugin.js:151:5)
    at moduleAdd (/app/node_modules/webpack/lib/ProgressPlugin.js:163:5)
    at SyncHook.eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:11:1)
    at Compilation.buildModule (/app/node_modules/webpack/lib/Compilation.js:634:26)
    at factory.create (/app/node_modules/webpack/lib/Compilation.js:884:14)
    at factory (/app/node_modules/webpack/lib/NormalModuleFactory.js:405:6)
    at hooks.afterResolve.callAsync (/app/node_modules/webpack/lib/NormalModuleFactory.js:155:13)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at resolver (/app/node_modules/webpack/lib/NormalModuleFactory.js:138:29)
    at process.nextTick (/app/node_modules/webpack/lib/NormalModuleFactory.js:342:9)
    at process._tickCallback (internal/process/next_tick.js:61:11)

Fixes a case in which we tried to send data through a socket that isn't connected due to the client being in the middle of a page reload (and thus closing the connection). This exception killed the whole webpack process.

Example stacktrace:

```
uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
    at WebSocket.send (/app/node_modules/ws/lib/websocket.js:322:19)
    at WebpackPluginServe.socket.progress (/app/node_modules/webpack-plugin-serve/lib/routes.js:87:16)
    at WebpackPluginServe.emit (events.js:189:13)
    at ProgressPlugin (/app/node_modules/webpack-plugin-serve/lib/index.js:212:16)
    at update (/app/node_modules/webpack/lib/ProgressPlugin.js:151:5)
    at moduleAdd (/app/node_modules/webpack/lib/ProgressPlugin.js:163:5)
    at SyncHook.eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:11:1)
    at Compilation.buildModule (/app/node_modules/webpack/lib/Compilation.js:634:26)
    at factory.create (/app/node_modules/webpack/lib/Compilation.js:884:14)
    at factory (/app/node_modules/webpack/lib/NormalModuleFactory.js:405:6)
    at hooks.afterResolve.callAsync (/app/node_modules/webpack/lib/NormalModuleFactory.js:155:13)
    at AsyncSeriesWaterfallHook.eval [as callAsync] (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
    at resolver (/app/node_modules/webpack/lib/NormalModuleFactory.js:138:29)
    at process.nextTick (/app/node_modules/webpack/lib/NormalModuleFactory.js:342:9)
    at process._tickCallback (internal/process/next_tick.js:61:11)
```
};

socket.progress = (data) => {
if (socket.readyState !== 1) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with the change. But it begs the question: should we wrap socket.send and inject that same logical check so all attempts to socket.send are covered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable, it should prevent any other such problems. I'll look into it.

@shellscape
Copy link
Owner

Going to merge this for now as it fixes a real problem. We can circle back to a more comprehensive fix later on.

@shellscape shellscape merged commit a11059c into shellscape:master Feb 20, 2019
@niieani niieani deleted the patch-1 branch February 20, 2019 18:10
@niieani
Copy link
Contributor Author

niieani commented Feb 20, 2019

Thanks @shellscape!

@shellscape shellscape mentioned this pull request Mar 19, 2019
18 tasks
niieani added a commit to niieani/webpack-plugin-serve that referenced this pull request Apr 29, 2019
Follow up to shellscape#113.

Even with the above fix, I encountered a similar issue, this time in the `invalid` handler:

```
uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
     at WebSocket.send (/app/node_modules/webpack-plugin-serve/node_modules/ws/lib/websocket.js:322:19)
     at WebpackPluginServe.socket.invalid (/app/node_modules/webpack-plugin-serve/lib/routes.js:83:16)
     at WebpackPluginServe.emit (events.js:189:13)
     at invalid.tap (/app/node_modules/webpack-plugin-serve/lib/index.js:155:41)
     at SyncHook.eval (eval at create (/app/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
     at Watchpack.watcher.compiler.watchFileSystem.watch (/app/node_modules/webpack/lib/Watching.js:139:33)
     at Object.onceWrapper (events.js:277:13)
     at Watchpack.emit (events.js:189:13)
     at Watchpack._onChange (/app/node_modules/watchpack/lib/watchpack.js:118:7)
     at Watchpack.<anonymous> (/app/node_modules/watchpack/lib/watchpack.js:99:8)
     at Watcher.emit (events.js:189:13)
     at /app/node_modules/watchpack/lib/DirectoryWatcher.js:109:7
     at Array.forEach (<anonymous>)
     at DirectoryWatcher.setFileTime (/app/node_modules/watchpack/lib/DirectoryWatcher.js:108:41)
     at DirectoryWatcher.onChange (/app/node_modules/watchpack/lib/DirectoryWatcher.js:264:7)
     at FSWatcher.emit (events.js:189:13)
     at FSWatcher.<anonymous> (/app/node_modules/watchpack/node_modules/chokidar/index.js:199:15)
     at /app/node_modules/watchpack/node_modules/chokidar/index.js:238:7
     at FSReqWrap.oncomplete (fs.js:155:5)
```

As suggested in shellscape#113 (comment) I've wrapped `send` so the error should not come back anymore.
niieani added a commit to niieani/webpack-plugin-serve that referenced this pull request May 1, 2019
Follow up to shellscape#113.

Even with the above fix, I encountered a similar issue, this time in the `invalid` handler:

```
uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
     at WebSocket.send (/app/node_modules/webpack-plugin-serve/node_modules/ws/lib/websocket.js:322:19)
     at WebpackPluginServe.socket.invalid (/app/node_modules/webpack-plugin-serve/lib/routes.js:83:16)
     at WebpackPluginServe.emit (events.js:189:13)
     at invalid.tap (/app/node_modules/webpack-plugin-serve/lib/index.js:155:41)
     at SyncHook.eval (eval at create (/app/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
     at Watchpack.watcher.compiler.watchFileSystem.watch (/app/node_modules/webpack/lib/Watching.js:139:33)
     at Object.onceWrapper (events.js:277:13)
     at Watchpack.emit (events.js:189:13)
     at Watchpack._onChange (/app/node_modules/watchpack/lib/watchpack.js:118:7)
     at Watchpack.<anonymous> (/app/node_modules/watchpack/lib/watchpack.js:99:8)
     at Watcher.emit (events.js:189:13)
     at /app/node_modules/watchpack/lib/DirectoryWatcher.js:109:7
     at Array.forEach (<anonymous>)
     at DirectoryWatcher.setFileTime (/app/node_modules/watchpack/lib/DirectoryWatcher.js:108:41)
     at DirectoryWatcher.onChange (/app/node_modules/watchpack/lib/DirectoryWatcher.js:264:7)
     at FSWatcher.emit (events.js:189:13)
     at FSWatcher.<anonymous> (/app/node_modules/watchpack/node_modules/chokidar/index.js:199:15)
     at /app/node_modules/watchpack/node_modules/chokidar/index.js:238:7
     at FSReqWrap.oncomplete (fs.js:155:5)
```

As suggested in shellscape#113 (comment) I've wrapped `send` so the error should not come back anymore.
shellscape pushed a commit that referenced this pull request May 1, 2019
Follow up to #113.

Even with the above fix, I encountered a similar issue, this time in the `invalid` handler:

```
uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
     at WebSocket.send (/app/node_modules/webpack-plugin-serve/node_modules/ws/lib/websocket.js:322:19)
     at WebpackPluginServe.socket.invalid (/app/node_modules/webpack-plugin-serve/lib/routes.js:83:16)
     at WebpackPluginServe.emit (events.js:189:13)
     at invalid.tap (/app/node_modules/webpack-plugin-serve/lib/index.js:155:41)
     at SyncHook.eval (eval at create (/app/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
     at Watchpack.watcher.compiler.watchFileSystem.watch (/app/node_modules/webpack/lib/Watching.js:139:33)
     at Object.onceWrapper (events.js:277:13)
     at Watchpack.emit (events.js:189:13)
     at Watchpack._onChange (/app/node_modules/watchpack/lib/watchpack.js:118:7)
     at Watchpack.<anonymous> (/app/node_modules/watchpack/lib/watchpack.js:99:8)
     at Watcher.emit (events.js:189:13)
     at /app/node_modules/watchpack/lib/DirectoryWatcher.js:109:7
     at Array.forEach (<anonymous>)
     at DirectoryWatcher.setFileTime (/app/node_modules/watchpack/lib/DirectoryWatcher.js:108:41)
     at DirectoryWatcher.onChange (/app/node_modules/watchpack/lib/DirectoryWatcher.js:264:7)
     at FSWatcher.emit (events.js:189:13)
     at FSWatcher.<anonymous> (/app/node_modules/watchpack/node_modules/chokidar/index.js:199:15)
     at /app/node_modules/watchpack/node_modules/chokidar/index.js:238:7
     at FSReqWrap.oncomplete (fs.js:155:5)
```

As suggested in #113 (comment) I've wrapped `send` so the error should not come back anymore.
smashercosmo pushed a commit to smashercosmo/webpack-plugin-serve that referenced this pull request Jul 23, 2019
smashercosmo pushed a commit to smashercosmo/webpack-plugin-serve that referenced this pull request Jul 23, 2019
Follow up to shellscape#113.

Even with the above fix, I encountered a similar issue, this time in the `invalid` handler:

```
uncaughtException Error: WebSocket is not open: readyState 2 (CLOSING)
     at WebSocket.send (/app/node_modules/webpack-plugin-serve/node_modules/ws/lib/websocket.js:322:19)
     at WebpackPluginServe.socket.invalid (/app/node_modules/webpack-plugin-serve/lib/routes.js:83:16)
     at WebpackPluginServe.emit (events.js:189:13)
     at invalid.tap (/app/node_modules/webpack-plugin-serve/lib/index.js:155:41)
     at SyncHook.eval (eval at create (/app/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:19:10), <anonymous>:7:1)
     at Watchpack.watcher.compiler.watchFileSystem.watch (/app/node_modules/webpack/lib/Watching.js:139:33)
     at Object.onceWrapper (events.js:277:13)
     at Watchpack.emit (events.js:189:13)
     at Watchpack._onChange (/app/node_modules/watchpack/lib/watchpack.js:118:7)
     at Watchpack.<anonymous> (/app/node_modules/watchpack/lib/watchpack.js:99:8)
     at Watcher.emit (events.js:189:13)
     at /app/node_modules/watchpack/lib/DirectoryWatcher.js:109:7
     at Array.forEach (<anonymous>)
     at DirectoryWatcher.setFileTime (/app/node_modules/watchpack/lib/DirectoryWatcher.js:108:41)
     at DirectoryWatcher.onChange (/app/node_modules/watchpack/lib/DirectoryWatcher.js:264:7)
     at FSWatcher.emit (events.js:189:13)
     at FSWatcher.<anonymous> (/app/node_modules/watchpack/node_modules/chokidar/index.js:199:15)
     at /app/node_modules/watchpack/node_modules/chokidar/index.js:238:7
     at FSReqWrap.oncomplete (fs.js:155:5)
```

As suggested in shellscape#113 (comment) I've wrapped `send` so the error should not come back anymore.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants