Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: catch listen error #34

Merged
merged 4 commits into from
Dec 8, 2022
Merged

Conversation

mpetrunic
Copy link

This should fix it but for whatever reason it's not working. Please help.

Related to: libp2p/js-libp2p-websockets#184 (comment)

@mpetrunic
Copy link
Author

cc @achingbrain

@codecov
Copy link

codecov bot commented Dec 6, 2022

Codecov Report

Merging #34 (b18ca2e) into master (3dea637) will increase coverage by 0.04%.
The diff coverage is 86.66%.

@@            Coverage Diff             @@
##           master      #34      +/-   ##
==========================================
+ Coverage   96.02%   96.07%   +0.04%     
==========================================
  Files          22       22              
  Lines         957      967      +10     
  Branches      158      160       +2     
==========================================
+ Hits          919      929      +10     
  Misses         38       38              
Flag Coverage Δ
chrome 100.00% <ø> (ø)
node 96.06% <86.66%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/server.ts 92.72% <83.78%> (+0.13%) ⬆️
test/server-address.spec.ts 92.00% <100.00%> (+3.76%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@achingbrain
Copy link
Collaborator

The reason this is failing is because the websocket server forwards any error events emitted by the underlying http(s) server when it's passed as an option.

If you stick a wsServer.on('error', () => {}) after wsServer is created the test passes (almost, the message assertion needs updating to something like await expect(server2.listen(55215)).to.eventually.be.rejected.with.property('message').that.include('EADDRINUSE')).

We probably want to be a bit smarter about error handling than that though.

We could update the internal Server class to create theWSServer instance in the listen method, call .listen on the underlying http(s) server but resolve the promise on the WSServer events?

@mpetrunic
Copy link
Author

@achingbrain It works now. Hope I didn't do anything stupid 😅

src/server.ts Outdated Show resolved Hide resolved
Co-authored-by: Alex Potsides <alex@achingbrain.net>
@achingbrain achingbrain merged commit 7a96e45 into alanshaw:master Dec 8, 2022
github-actions bot pushed a commit that referenced this pull request Dec 8, 2022
## [5.0.6](v5.0.5...v5.0.6) (2022-12-08)

### Bug Fixes

* catch listen error ([#34](#34)) ([7a96e45](7a96e45))
@github-actions
Copy link

github-actions bot commented Dec 8, 2022

🎉 This PR is included in version 5.0.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants