You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Panic when flushing http response in engine #10228
The issue seems to be a double close on the value of (*engine.Job).Stdout when calling (*TagStore).pushV2Repository from (*TagStore).CmdPush. job.Stdout is allocated as a (*utils.WriteFlusher) and flows into (*Session).PutV2ImageBlob through the out argument of ProgressReader. When the job completes, during some server error, the call stack returns early, closing all of the output streams. Because (*engine.Job).Stdout was associated with an *http.Request in (*Session).PutV2ImageBlob, the http package also attempts to shutdown the writer, resulting in a panic. The confusing aspect here is that (*engine.Job).Stdout, an io.Writer is linked to the lifecycle of the http.Request through the ProgressReader.
This simply detaches the (*engine.Job).Stdout from the http package, leaving control over the lifecycle of the body up to the caller.
There are other solutions that may help:
Remove the use of ioutils.WriteFlusher. This object tries to synchronize writes and flushes without managing the close aspect. An all in one line buffering, that correctly synchronizes Close may help.
Another solution (thanks @dmcgowan) is to allow multiple closes on *engine.Output but setting the dests field to nil after a Close, relegating subsequent closes to noops.
Maybe a better fix would be to prevent a double close on the progress reader since it writes some final bytes to the underlying writer before doing a close, it's not re-entrant
Activity
BrianBland commentedon Jan 20, 2015
I received the same issue when pushing (504 error on layer upload). Stack trace here.
stevvooe commentedon Jan 20, 2015
For reference, @BrianBland encountered this panic with the binaries from here: #9784 (comment).
stevvooe commentedon Jan 21, 2015
The issue seems to be a double close on the value of
(*engine.Job).Stdoutwhen calling(*TagStore).pushV2Repositoryfrom(*TagStore).CmdPush.job.Stdoutis allocated as a(*utils.WriteFlusher)and flows into(*Session).PutV2ImageBlobthrough theoutargument ofProgressReader. When the job completes, during some server error, the call stack returns early, closing all of the output streams. Because(*engine.Job).Stdoutwas associated with an*http.Requestin(*Session).PutV2ImageBlob, thehttppackage also attempts to shutdown the writer, resulting in a panic. The confusing aspect here is that(*engine.Job).Stdout, anio.Writeris linked to the lifecycle of thehttp.Requestthrough theProgressReader.The simplest solution is something like this:
This simply detaches the
(*engine.Job).Stdoutfrom thehttppackage, leaving control over the lifecycle of the body up to the caller.There are other solutions that may help:
ioutils.WriteFlusher. This object tries to synchronize writes and flushes without managing the close aspect. An all in one line buffering, that correctly synchronizesClosemay help.*engine.Outputbut setting thedestsfield to nil after a Close, relegating subsequent closes to noops.jessfraz commentedon Jan 21, 2015
I wish there was a way to test it
dmcgowan commentedon Jan 21, 2015
The fix I am trying to test (still haven't been able to reproduce)
LK4D4 commentedon Jan 21, 2015
@dmcgowan seems legit. Still not sure how to reproduce this :/
tiborvass commentedon Jan 21, 2015
Have trouble reproducing it now :(
tiborvass commentedon Jan 21, 2015
@stevvooe @dmcgowan sorry guys, I tried to reproduce it but can't. Should we still make one of those changes? /cc @jfrazelle @LK4D4 @icecrime
LK4D4 commentedon Jan 21, 2015
@tiborvass
nil-ing dests seems good thing to do. We can try.Reproducing of crash is pretty hard really because it's involving network failures.
icecrime commentedon Jan 21, 2015
I just looked into
engine/streams.goand I see no code path wheredestsbeingnilcould have unwanted side effects, so it's worth trying.stevvooe commentedon Jan 21, 2015
@icecrime @LK4D4 @tiborvass @dmcgowan @jfrazelle Please talk to @BrianBland about a reproduction. He has seen the crash several times.
crosbymichael commentedon Jan 21, 2015
Maybe a better fix would be to prevent a double close on the progress reader since it writes some final bytes to the underlying writer before doing a close, it's not re-entrant
stevvooe commentedon Jan 21, 2015
@crosbymichael That is probably the "write" fix.
I have a small patch to change
WriteFlusherto intercept close correctly. I'll try to get that out today.dmcgowan commentedon Jan 22, 2015
Also #9913 appears to be the same panic during a v1 registry operation
stevvooe commentedon Jan 22, 2015
I have a minimal reproduction and have filed golang/go#9657.
stevvooe commentedon Jan 22, 2015
@icecrime Update: bug was insta-closed. Basically, providing the noop closer in #10244 should fix the problem by leaving body lifecycle to calling function (which is actually the server-side of the http server). There is more history here: https://groups.google.com/forum/#!msg/golang-dev/o9i_SbGRrzI/n4FPqT1eLlYJ.
jessfraz commentedon Jan 22, 2015
closed by #10244