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

Feat/log on closed connections #123

Closed
wants to merge 4 commits into from

Conversation

jmealo
Copy link
Contributor

@jmealo jmealo commented Feb 20, 2021

This PR fixes the git oops in #117 authored by @dalexanco

Minor change:
I decided not to attach/detach a listener for the finish event when we don't plan on logging it. This shouldn't leave any dangling handlers or change the intended behavior.

Tests pass.

@mcollina
Copy link
Member

I don't think writableEnded is there in node v10.

@jmealo
Copy link
Contributor Author

jmealo commented Feb 20, 2021

@mcollina: I verified this fails on Node 10 locally and passed up to 15. I think that you're on to something.

@jmealo
Copy link
Contributor Author

jmealo commented Feb 20, 2021

@mcollina: I reviewed (and you reviewed apparently :D) the PR where writableEnded landed: https://github.com/nodejs/node/pull/28934/files

I wasn't sure if we exited early based on the order of events firing, so I removed my listener tweak before I got started.

I tried to backport this to Node.js 10 using this._writableState.ending but it doesn't look like that's exposed to userland? Any thoughts?

@jmealo jmealo force-pushed the feat/log_on_closed_connections branch 3 times, most recently from aafe442 to a473a33 Compare February 21, 2021 02:48
@jmealo
Copy link
Contributor Author

jmealo commented Feb 21, 2021

@mcollina: I think this works best. Let me know what you think.

@jmealo jmealo force-pushed the feat/log_on_closed_connections branch from a473a33 to d1afd5b Compare February 21, 2021 02:51
@jmealo
Copy link
Contributor Author

jmealo commented Feb 21, 2021

@mcollina: Here's what I landed on:

Behavior:
If a user tries to log unfinished connections and writableEnded isn't available; we throw:'onlyLogFinishedRequest': false requires Node v12.9.0 or later at start-up.

Reasoning:
Node 10 is EoL in April and it wasn't immediately obvious for me how to back-port this. We already throw on other invalid parameter combinations. This seems like reasonable behavior given the circumstances.

var line = dest.read()
t.equal(line, null)
t.end()
}, 100)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a setImmediate() instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm... The tests were the only thing I didn't rewrite; I can take a look at these later today. I don't see why not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mcollina: I wasn't able to completely replace setTimeout with setImmediate without a triple nested setImmediate which seemed worse from a clarity standpoint. The author's original intent was to give the request enough time to start so a failure could be simulated and ultimately logged. One or two of these setTimeout can be easily replaced with setImmediate. To completely remove setTimeout would require more work than I can set aside right now. I may be able to revisit later -- or anyone else is free to pick this up as well! It's a good task for those looking to learn about the particulars of the event loop.

Copy link
Member

Choose a reason for hiding this comment

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

using setTimeout will lead to flaky CI runs, I really need this fixed before landing.

Another approach is using some logical events instead of waiting.

var line = dest.read()
t.equal(line.finished, false, 'unfinished request is logged and flagged')
t.end()
}, 100)
Copy link
Member

Choose a reason for hiding this comment

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

Can you use a setImmediate() instead?

@@ -15,6 +16,9 @@ function setup (t, logger, cb, handler) {
if (req.url === '/') {
res.end('hello world')
return
} else if (req.url === WAIT_URL) {
setTimeout(() => res.end('that was boring'), 300)
Copy link
Member

Choose a reason for hiding this comment

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

why a setTimeout? Can you use a setImmediate() instead?

@mcollina
Copy link
Member

mcollina commented Jul 4, 2022

closed for no activity

@mcollina mcollina closed this Jul 4, 2022
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.

4 participants