Skip to content

fix(server): respect sockPath on transportMode: 'ws' (#2310)#2311

Merged
hiroppy merged 2 commits into
webpack:masterfrom
joonas-lahtinen:fix/transportMode-ws-proxy
Nov 29, 2019
Merged

fix(server): respect sockPath on transportMode: 'ws' (#2310)#2311
hiroppy merged 2 commits into
webpack:masterfrom
joonas-lahtinen:fix/transportMode-ws-proxy

Conversation

@joonas-lahtinen

Copy link
Copy Markdown
Contributor
  • This is a bugfix
  • This is a feature
  • This is a code refactor
  • This is a test update
  • This is a docs update
  • This is a metadata update

For Bugs and Features; did you add new tests?

Added tests to verify that sockPath is respected.

Motivation / Use-Case

Fixes bug #2310.

@jsf-clabot

jsf-clabot commented Nov 9, 2019

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Nov 9, 2019

Copy link
Copy Markdown

Codecov Report

Merging #2311 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2311      +/-   ##
==========================================
+ Coverage   93.84%   93.86%   +0.02%     
==========================================
  Files          34       34              
  Lines        1283     1288       +5     
  Branches      366      367       +1     
==========================================
+ Hits         1204     1209       +5     
  Misses         78       78              
  Partials        1        1
Impacted Files Coverage Δ
lib/servers/WebsocketServer.js 91.66% <100%> (+2.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3a31917...976e0cf. Read the comment docs.

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/cc @Loonride

@alexander-akait

Copy link
Copy Markdown
Member

Please accept CLA

Comment thread lib/servers/WebsocketServer.js Outdated
}

shouldUpgrade(req) {
const pathname = url.parse(req.url).pathname;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

memo: we'll use URLSearchParams after major release.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@joonas-lahtinen joonas-lahtinen force-pushed the fix/transportMode-ws-proxy branch from ee3e805 to 6bcddc9 Compare November 9, 2019 14:28
@joonas-lahtinen

Copy link
Copy Markdown
Contributor Author

Thanks for the quick reviews. I noticed a bug in the tests based on the code coverage difference report, should be fixed now and using the more forward compatible ws.Server.shouldHandle()

@joonas-lahtinen

joonas-lahtinen commented Nov 9, 2019

Copy link
Copy Markdown
Contributor Author

This also fixes the bug that whole webpack-dev-server process exits due to an unhandled error if the proxy target is not open:

[HPM] Rewriting path from "/api" to ""
[HPM] GET /api ~> http://localhost:8888
[HPM] Upgrading to WebSocket
events.js:174
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/cc @hiroppy @Loonride wait both reviews

@knagaitsev knagaitsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@joonas-lahtinen I ran your new tests without the changes that you made, and they passed. How are your changes different from the existing behavior? The ws docs say for the path option - "Accept only connections matching this path" (https://github.com/websockets/ws/blob/master/doc/ws.md#new-websocketserveroptions-callback), so paths that do not match the one specified are already rejected.

Edit: I missed the explanation in #2310. Could you make a test demonstrating that proxying works?

@joonas-lahtinen

Copy link
Copy Markdown
Contributor Author

Thanks for the patience. After some digging I found the spot to inject testing the different transportMode options with proxy.

@knagaitsev

Copy link
Copy Markdown
Contributor

LGTM /cc @evilebottnawi @hiroppy

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/cc @hiroppy

@hiroppy hiroppy merged commit e188542 into webpack:master Nov 29, 2019
@hiroppy

hiroppy commented Nov 29, 2019

Copy link
Copy Markdown
Contributor

thanks

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.

5 participants