Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Socket close handler not working in browser setting #179

Closed
felixSchl opened this issue Aug 30, 2022 · 1 comment · Fixed by #183
Closed

Socket close handler not working in browser setting #179

felixSchl opened this issue Aug 30, 2022 · 1 comment · Fixed by #183
Labels
need/triage Needs initial labeling and prioritization released

Comments

@felixSchl
Copy link

Hey, I noticed the socket close handler is not working in the browser

stream.socket.once != null && stream.socket.once('close', () => { // eslint-disable-line @typescript-eslint/prefer-optional-chain
// In instances where `close` was not explicitly called,
// such as an iterable stream ending, ensure we have set the close
// timeline
if (maConn.timeline.close == null) {
maConn.timeline.close = Date.now()
}
})
. To verify I have locally edited socket-to-conn.js and replaced the .once stuff with this:

function onclose () {
    if (stream.socket.onclose === onclose) {
        stream.socket.onclose = null; // only once
    }
    if (maConn.timeline.close == null) {
        maConn.timeline.close = Date.now();
    }
}
stream.socket.onclose = onclose;

It has the downside of mutating the object so there might be a better solution, but it works.

@mpetrunic mpetrunic added the need/triage Needs initial labeling and prioritization label Aug 30, 2022
achingbrain pushed a commit that referenced this issue Sep 21, 2022
I simulated that it's not working by attaching a socket to a conn object that I can manually close. Not sure how to trigger the close socket event without hacking (or without calling close on conn)

resolves #179
github-actions bot pushed a commit that referenced this issue Sep 21, 2022
## [3.0.4](v3.0.3...v3.0.4) (2022-09-21)

### Bug Fixes

* remove set timeout ([#182](#182)) ([23518b0](23518b0)), closes [#121](#121)
* socket close event not working in browser ([#183](#183)) ([9076b5b](9076b5b)), closes [#179](#179)

### Trivial Changes

* Update .github/workflows/stale.yml [skip ci] ([64411ee](64411ee))

### Dependencies

* update @multiformats/multiaddr to 11.0.0 ([#185](#185)) ([539db88](539db88))
@github-actions
Copy link

🎉 This issue has been resolved in version 3.0.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization released
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants