docker-modem
docker-modem copied to clipboard
dial() can call callback multiple times
Modem.prototype.dial can call its callback multiple times, which violates that principle that Node-style callbacks of this type should be invoked only once with either an error or a result. This appears because it attaches listeners to the response and error callbacks. In our scenario, we observed a case where we'd see a response event and a subsequent error event with an ECONNRESET. We were never able to determine exactly why the Docker daemon was resetting the connection after a response. It's possible that this is an issue upstream in Node's http module, although that seems unlikely.
Regardless of this underlying cause, I believe it's this library's responsibility to ensure that the callback is only called a single time. If a maintainer can confirm this, I'd be happy to attempt making that change in a PR.
Here's an issue where we were investigating this: https://github.com/PrairieLearn/PrairieLearn/issues/5669. I've reproduced the relevant information above, but I'm including a link here in case someone wants to see our code that was interacting with this library via dockerode.
@apocas Bump -- @nwalters512 wrapped this behavior in a Promise to ensure it would only be resolved once. Would that be appropriate to do in the library in general?
Interesting, curious about the underlying cause. docker-engine's HTTP management isn't the great also, so it could also be a problem there.
Nevertheless going to implement a simple/nasty control to ensure that the callback is called only once and this way avoid any breaking change.