10000 fix bug: headers are changed after log entry emits by osher · Pull Request #258 · log4js-node/log4js-node · GitHub
[go: up one dir, main page]

Skip to content

fix bug: headers are changed after log entry emits #258

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

Merged
merged 3 commits into from
Nov 15, 2014
Merged

fix bug: headers are changed after log entry emits #258

merged 3 commits into from
Nov 15, 2014

Conversation

osher
Copy link
Contributor
@osher osher commented Nov 4, 2014

In the original version, the following operation looks synchronic, however it is not:

res.end = end;
res.end(data,enc);

//emit the log entry 

In fact, it starts a series of async operations, in which the request may yet be changed after the request log has already been emitted
(in our case - a change on request headers was observed, probably by some low level hook or hacky wrap of some http.ServerResponse method that's involved on the process - but called asynchronously)
what leads to situation that the request log does not capture valid data.
(observed by us:

  • request headers
  • calculated end time, when concerning big content
    )

First, the fix just used setTimeout(function() { /*emit the log entry*/ }, 5), but I'm afraid it may not hold true for big contents.
Well. maybe the headers part will, but the response time calculation will lie.

The fix relays on: http://nodejs.org/api/http.html#http_event_finish

In the original version, the following operation looks synchronic, however it is not:

```
res.end = end;
res.end(data,enc);

//emit the log entry 
```

In fact, it starts a series of async operations, in which the request may yet be changed after the request log has already been emitted
(in our case - a change
8000
 on request headers was observed, probably by some low level hook or hacky wrap of some http.ServerResponse method that's involved on the process - but called asynchronously)
what leads to situation that the request log does not capture valid data.
(observed by us:
 - request headers
 - calculated end time, when concerning big content
)

The fix just used `setTimeout(function() { /*emit the log entry*/ }, 1)`, but I'm afraid it may not hold true for big contents.
Well. maybe the headers part will, but the response time calculation will lie.

The fix relays on: http://nodejs.org/api/http.html#http_event_finish
@osher
Copy link
Contributor Author
osher commented Nov 5, 2014

You got to be kidding
Your test suite actually assumes the operation is synchronized...

But I'm on it.

@osher
Copy link
Contributor Author
osher commented Nov 5, 2014

Ok, that does it :)

@nomiddlename
Copy link
Collaborator

I was worried in your description that you'd just put "setTimeout" in the code, but listening for the request "finish" event makes sense. Thanks.

nomiddlename added a commit that referenced this pull request Nov 15, 2014
fix bug: headers are changed after log entry emits
@nomiddlename nomiddlename merged commit ec5f448 into log4js-node:master Nov 15, 2014
@osher osher deleted the patch-4 branch November 25, 2014 09:27
@osher osher restored the patch-4 branch November 25, 2014 09:27
@osher osher deleted the patch-4 branch November 25, 2014 09:27
@osher
Copy link
Contributor Author
osher commented Nov 25, 2014

I see this PR made it to the master branch, but it's yet to be published.

Say, when do we expect the next version publish?

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.

2 participants
0