@@ -39,7 +39,7 @@ type HijackedIOStreamer struct {
3939// to/from the hijacked connection, blocking until it is either done reading
4040// output, the user inputs the detach key sequence when in TTY mode, or when
4141// the given context is cancelled.
42- func (h * HijackedIOStreamer ) Stream (ctx context.Context ) error {
42+ func (h * HijackedIOStreamer ) Stream (ctx context.Context , readTimeout time. Duration ) error {
4343 restoreInput , err := h .setupInput ()
4444 if err != nil {
4545 return errors .Errorf ("unable to setup input stream: %s" , err )
@@ -48,7 +48,7 @@ func (h *HijackedIOStreamer) Stream(ctx context.Context) error {
4848 defer restoreInput ()
4949 defer h .Resp .Close ()
5050 outputDone := h .beginOutputStream (restoreInput )
51- inputDone , detached := h .beginInputStream (ctx , restoreInput )
51+ inputDone , detached := h .beginInputStream (ctx , restoreInput , readTimeout )
5252
5353 select {
5454 case err = <- outputDone :
@@ -145,7 +145,7 @@ func (h *HijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
145145
146146var errInvalidWrite = errors .New ("invalid write result" )
147147
148- func Copy (ctx context.Context , dst net.Conn , src io.Reader ) (written int64 , err error ) {
148+ func Copy (ctx context.Context , dst net.Conn , src io.Reader , readTimeout time. Duration ) (written int64 , err error ) {
149149 size := 32 * 1024
150150 buf := make ([]byte , size )
151151 for {
@@ -158,7 +158,7 @@ func Copy(ctx context.Context, dst net.Conn, src io.Reader) (written int64, err
158158 nr , er := src .Read (buf )
159159 if nr > 0 {
160160 // docker container is stop check
161- err = dst .SetReadDeadline (time .Now ().Add (time . Second * 3 ))
161+ err = dst .SetReadDeadline (time .Now ().Add (readTimeout ))
162162 if err != nil {
163163 break
164164 }
@@ -189,13 +189,13 @@ func Copy(ctx context.Context, dst net.Conn, src io.Reader) (written int64, err
189189 return
190190}
191191
192- func (h * HijackedIOStreamer ) beginInputStream (ctx context.Context , restoreInput func ()) (doneC <- chan struct {}, detachedC <- chan error ) {
192+ func (h * HijackedIOStreamer ) beginInputStream (ctx context.Context , restoreInput func (), readTimeout time. Duration ) (doneC <- chan struct {}, detachedC <- chan error ) {
193193 inputDone := make (chan struct {})
194194 detached := make (chan error )
195195
196196 go func () {
197197 if h .InputStream != nil {
198- _ , err := Copy (ctx , h .Resp .Conn , h .InputStream )
198+ _ , err := Copy (ctx , h .Resp .Conn , h .InputStream , readTimeout )
199199 restoreInput ()
200200
201201 logrus .Debug ("[hijack] End of stdin" )
0 commit comments