Skip to content

ensure hijackedConn implements CloseWrite function#36517

Merged
thaJeztah merged 1 commit into
moby:masterfrom
jim-minter:missing_closewrite
Mar 14, 2018
Merged

ensure hijackedConn implements CloseWrite function#36517
thaJeztah merged 1 commit into
moby:masterfrom
jim-minter:missing_closewrite

Conversation

@jim-minter
Copy link
Copy Markdown
Contributor

Fixes #36516

@jim-minter jim-minter requested a review from dnephin as a code owner March 7, 2018 18:32
jim-minter pushed a commit to jim-minter/source-to-image that referenced this pull request Mar 7, 2018
jim-minter pushed a commit to jim-minter/origin that referenced this pull request Mar 7, 2018
jim-minter pushed a commit to jim-minter/origin that referenced this pull request Mar 7, 2018
jim-minter pushed a commit to jim-minter/source-to-image that referenced this pull request Mar 7, 2018
@tophj-ibm
Copy link
Copy Markdown
Contributor

ignore powerpc failure, unrelated and debugging.

openshift-merge-robot added a commit to openshift/origin that referenced this pull request Mar 7, 2018
Automatic merge from submit-queue.

UPSTREAM: <carry>: ensure hijackedConn implements CloseWrite function

moby/moby#36516
moby/moby#36517
@mrunalp
Copy link
Copy Markdown
Contributor

mrunalp commented Mar 8, 2018

@runcom @thaJeztah ping

@runcom
Copy link
Copy Markdown
Member

runcom commented Mar 8, 2018

LGTM ping @cpuguy83

@thaJeztah
Copy link
Copy Markdown
Member

Thanks! Is is possible to have a test for this?

@thaJeztah
Copy link
Copy Markdown
Member

PowerPC failures are not related

@thaJeztah
Copy link
Copy Markdown
Member

nit: perhaps would be good to have the description of #36516 in the commit-message

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Mar 8, 2018

It would be good to only implement CloseWrite if the underlying conn does.

@cpuguy83
Copy link
Copy Markdown
Member

cpuguy83 commented Mar 8, 2018

Also we should think about removing this, I think?

@jim-minter jim-minter force-pushed the missing_closewrite branch from 209657e to 80ecc25 Compare March 8, 2018 18:15
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 8, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@592a15b). Click here to learn what that means.
The diff coverage is 0%.

@@            Coverage Diff            @@
##             master   #36517   +/-   ##
=========================================
  Coverage          ?   35.13%           
=========================================
  Files             ?      613           
  Lines             ?    45639           
  Branches          ?        0           
=========================================
  Hits              ?    16036           
  Misses            ?    27462           
  Partials          ?     2141

@jim-minter
Copy link
Copy Markdown
Contributor Author

Repushed adding a type assertion and improving the commit message. Beyond the type assertion I can't see a straightforward test case for this?

bparees pushed a commit to bparees/source-to-image that referenced this pull request Mar 8, 2018
bparees pushed a commit to bparees/source-to-image that referenced this pull request Mar 8, 2018
bparees pushed a commit to bparees/source-to-image that referenced this pull request Mar 8, 2018
Copy link
Copy Markdown
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread client/hijack.go
// If there is buffered content, wrap the connection
c = &hijackedConn{c, br}
// If there is buffered content, wrap the connection. We return an
// object that implements CloseWrite iff the underlying connection
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor nit, s/iff/if/.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I actually meant iff, as in "if and only if" :)

@thaJeztah
Copy link
Copy Markdown
Member

@runcom still LGTY?

@runcom
Copy link
Copy Markdown
Member

runcom commented Mar 14, 2018

Yup!

@thaJeztah
Copy link
Copy Markdown
Member

test-failing is unrelated

@kolyshkin
Copy link
Copy Markdown
Contributor

kolyshkin commented Mar 23, 2018

Just to note that in a couple of other places we have something like this instead:

moby/client/hijack.go

Lines 26 to 33 in c3b3be5

func (c *tlsClientCon) CloseWrite() error {
// Go standard tls.Conn doesn't provide the CloseWrite() method so we do it
// on its underlying connection.
if conn, ok := c.rawConn.(types.CloseWriter); ok {
return conn.CloseWrite()
}
return nil
}

and this:

moby/api/types/client.go

Lines 133 to 139 in c3b3be5

// CloseWrite closes a readWriter for writing.
func (h *HijackedResponse) CloseWrite() error {
if conn, ok := h.Conn.(CloseWriter); ok {
return conn.CloseWrite()
}
return nil
}

Looking at this, I have two conflicting thoughts:

  1. we could use the same technique (i.e. call CloseWrite() if available, otherwise do nothing) for hijackedConn instead of implementing a separate hijackedConnCloseWriter.

  2. However, the code quoted above may not work right in this scenario:

    // CloseStreams ensures that a list for http streams are properly closed.
    func CloseStreams(streams ...interface{}) {
    for _, stream := range streams {
    if tcpc, ok := stream.(interface {
    CloseWrite() error
    }); ok {
    tcpc.CloseWrite()
    } else if closer, ok := stream.(io.Closer); ok {
    closer.Close()
    }
    }
    }

So, should we instead change the above two places to a hack similar to the one in this PR?

update: improve wording

@tonistiigi
Copy link
Copy Markdown
Member

@kolyshkin I think so. But we probably don't need as complicated fix. For tlsClientCon it seems that it is only needed if CloseWrite is supported. For HijackedResponse I really do not understand why this method(or Close) is defined at all. Conn is public and all clients can check it directly. I'd just remove it (at least CloseWrite).

@cpuguy83
Copy link
Copy Markdown
Member

We don't need tlsClientConn anymore since go1.8. I'm working on a PR to remove it but having some issues with my unit test hanging trying to setup the hijack.

jim-minter pushed a commit to jim-minter/origin that referenced this pull request Mar 26, 2018
CloseWrite whenever its underlying connection does.  If this isn't done, then a
container listening on stdin won't receive an EOF when the client closes the
stream at their end.

moby/moby#36516
moby/moby#36517
liggitt pushed a commit to openshift/moby-moby that referenced this pull request Mar 29, 2018
…rite function

moby#36516
moby#36517

Origin-commit: 99ac39cbfbec9459f085b9f6cf786945b9e00867
mrhyperbit23z0d added a commit to mrhyperbit23z0d/YfCloudKitp that referenced this pull request Jun 6, 2022
mrhyperbit23z0d added a commit to mrhyperbit23z0d/YfCloudKitp that referenced this pull request Jun 6, 2022
MachinesWhisper added a commit to MachinesWhisper/mdLinu that referenced this pull request Jul 29, 2025
MachinesWhisper added a commit to MachinesWhisper/mdLinu that referenced this pull request Jul 29, 2025
memaLuaeed added a commit to memaLuaeed/practical that referenced this pull request Jan 1, 2026
memaLuaeed added a commit to memaLuaeed/practical that referenced this pull request Jan 1, 2026
statelyaistate added a commit to statelyaistate/viz that referenced this pull request Jan 26, 2026
statelyaistate added a commit to statelyaistate/viz that referenced this pull request Jan 26, 2026
goldseyes added a commit to goldseyes/eureka that referenced this pull request Mar 18, 2026
goldseyes added a commit to goldseyes/eureka that referenced this pull request Mar 18, 2026
goldseyes added a commit to goldseyes/disco that referenced this pull request Mar 18, 2026
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.