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

ensure hijackedConn implements CloseWrite function #36517

Merged
merged 1 commit into from
Mar 14, 2018

Conversation

jim-minter
Copy link
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
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
Contributor

mrunalp commented Mar 8, 2018

@runcom @thaJeztah ping

@runcom
Copy link
Member

runcom commented Mar 8, 2018

LGTM ping @cpuguy83

@thaJeztah
Copy link
Member

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

@thaJeztah
Copy link
Member

PowerPC failures are not related

@thaJeztah
Copy link
Member

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

@cpuguy83
Copy link
Member

cpuguy83 commented Mar 8, 2018

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

@cpuguy83
Copy link
Member

cpuguy83 commented Mar 8, 2018

Also we should think about removing this, I think?

@codecov
Copy link

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
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?

@thaJeztah thaJeztah added this to backlog in maintainers-session Mar 8, 2018
@thaJeztah thaJeztah removed this from backlog in maintainers-session Mar 8, 2018
bparees pushed a commit to bparees/source-to-image that referenced this pull request Mar 8, 2018
client/hijack.go Outdated
// Conn.
var _ types.CloseWriter = &hijackedConn{}

func (c *hijackedConn) CloseWrite() error {
Copy link
Member

Choose a reason for hiding this comment

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

It seems we need two types and decide which one to use based on if the underlying conn supports CloseWrite, otherwise the caller will end up doing something like:

cw, ok := hijack.(types.CloseWriter)
if ok {
    return cw.CloseWrite
}
return hijack.Close()

Which would lead to a leaked fd.

@thaJeztah
Copy link
Member

Moved back to code-review per #36517 (comment), or could that change be done in a follow-up, @cpuguy83 ?

@cpuguy83
Copy link
Member

It'd be best to handle it here rather than in a follow-up.

…lying

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.

Signed-off-by: Jim Minter <jminter@redhat.com>
@jim-minter
Copy link
Contributor Author

@cpuguy83 repushed with an additional type - ptal
@mrunalp @runcom fyi

Copy link
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

// 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
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
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
Member

@runcom still LGTY?

@runcom
Copy link
Member

runcom commented Mar 14, 2018

Yup!

@thaJeztah
Copy link
Member

test-failing is unrelated

@kolyshkin
Copy link
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
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
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
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