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

Avoid panic on write after close in http #17634

Merged
merged 1 commit into from Nov 3, 2015

Conversation

stevvooe
Copy link
Contributor

@stevvooe stevvooe commented Nov 3, 2015

By adding a (*WriteFlusher).Close, we limit the Write calls to possibly
deallocated http response buffers to the lifetime of an http request.
Typically, this is seen as a very confusing panic, the cause is usually a
situation where an http.ResponseWriter is held after request completion. We
avoid the panic by disallowing further writes to the response writer after the
request is completed.

Closes #17625.

Signed-off-by: Stephen J Day stephen.day@docker.com

@@ -63,7 +63,9 @@ func (s *router) getContainersStats(ctx context.Context, w http.ResponseWriter,
w.Header().Set("Content-Type", "application/json")
out = w
} else {
out = ioutils.NewWriteFlusher(w)
wf := ioutils.NewWriteFlusher(w)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder what does this mean :)
Why not

out = ioutils.NewWriteFlusher(w)
defer out.Close()

?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, got it.

@tiborvass
Copy link
Contributor

@stevvooe tests are failing

n, err = wf.w.Write(b)
wf.flushed = true
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for removing this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(*WriteFlusher).Flush() sets it.

Copy link
Member

Choose a reason for hiding this comment

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

This is calling (http.Flusher).Flush()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry, this is terrible code. Fixing now.

@stevvooe stevvooe force-pushed the avoid-panic-on-flush branch 3 times, most recently from 13b4886 to ca6bd7e Compare November 3, 2015 01:40
By adding a (*WriteFlusher).Close, we limit the Write calls to possibly
deallocated http response buffers to the lifetime of an http request.
Typically, this is seen as a very confusing panic, the cause is usually a
situation where an http.ResponseWriter is held after request completion. We
avoid the panic by disallowing further writes to the response writer after the
request is completed.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
@tonistiigi
Copy link
Member

LGTM

1 similar comment
@LK4D4
Copy link
Contributor

LK4D4 commented Nov 3, 2015

LGTM

LK4D4 added a commit that referenced this pull request Nov 3, 2015
Avoid panic on write after close in http
@LK4D4 LK4D4 merged commit 3c695d7 into moby:master Nov 3, 2015
@stevvooe stevvooe deleted the avoid-panic-on-flush branch November 3, 2015 05:15
@tiborvass tiborvass modified the milestones: 1.9.1, 1.9.0 Nov 3, 2015
@thaJeztah thaJeztah mentioned this pull request Nov 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants