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

Enabling client process multiple GoAways #1393

Merged
merged 4 commits into from Jul 28, 2017
Merged

Conversation

MakMukhi
Copy link
Contributor

@MakMukhi MakMukhi commented Jul 26, 2017

#1387 The first of two parts.

@dfawley
Copy link
Member

dfawley commented Jul 26, 2017

Also, as discussed, please move all the go away handling code into handleGoAway.

clientconn.go Outdated
if drain {
t.GracefulClose()
} else {
if !drain {
Copy link
Member

Choose a reason for hiding this comment

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

if t != nil && !drain {
}

@@ -665,6 +665,16 @@ func (t *http2Client) GracefulClose() error {
// Notify the streams which were initiated after the server sent GOAWAY.
select {
case <-t.goAway:
// A client can recieve multiple GoAways from server (look at https://github.com/grpc/grpc-go/issues/1387).
// The idea is that the first GoAway will be sent with an ID of MaxInt32 and the second GoAway will be sent after an RTT delay
// with the an ID of the last stream the server will process.
Copy link
Member

Choose a reason for hiding this comment

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

s/an//

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Looking good, thanks. I have some more "great" ideas.

// close all streams created after the second GoAwayId. This way streams that were in-flight while the GoAway from server
// was being sent don't get killed.
//
// Note: to be backward compatible with servers that will still send only 1 GoAway we'll still try and close streams with ID
Copy link
Member

Choose a reason for hiding this comment

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

I would omit this comment, personally, or at least the backward compatible bit.. The spec requires this behavior.

if n == 0 && t.nextID > 1 {
n = t.nextID - 2
}
m := t.goAwayID + 2
Copy link
Member

Choose a reason for hiding this comment

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

pass goAwayID as a parameter (lastValidStreamID or something)? Then you can delete the field in http2client IIUC.

n = t.nextID - 2
}
m := t.goAwayID + 2
if m == 2 {
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 really a special case of a general problem.

If a server says GOAWAY(4), which is valid, we need to kill streams 5->max. This code does not handle that.

How about:

// Round to a multiple of two, then add one.
start := ((lastValidStreamID + 1) % 2) + 1

// Note: to be backward compatible with servers that will still send only 1 GoAway we'll still try and close streams with ID
// greater that GoAwayId sent by the first GoAway.

n := t.prevGoAwayID
Copy link
Member

Choose a reason for hiding this comment

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

Can you rename n -> end or something with meaning, please?

close(s.goAway)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

t.prevGoAwayID probably should be set to end - 2 here. Otherwise if we get

GOAWAY(INT32_MAX)
GOAWAY(0)

the second goaway will go through 1B iterations.

OR, we can do something like this, above:

if t.nextID == 1 {  // or len(t.activeStreams) == 0
  return // there are no streams to stop
}

end := t.prevGoAwayID
if end == 0 || end > t.nextID {
  end = t.nextID - 2
}

func (t *http2Client) GracefulClose() error {
t.mu.Lock()
if t.gracefulCloseLocked() {
t.mu.Unlock()
return t.Close()
Copy link
Member

Choose a reason for hiding this comment

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

How about doing the same thing with t.Close() ? t.closeLocked() which assumes t.mu is already taken.

If this ends up causing a bunch of work or ugliness, then don't. But there are other places that follow the unlock->Close() pattern. It's not a performance problem, since this is not a critical path, but I worry a bit about races if you give up the lock after you determine you should shut down but before doing so.

@@ -1008,13 +1024,25 @@ func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) {
}
t.prevGoAwayID = id
t.goAwayID = f.LastStreamID
t.goAwayActiveStreams()
shouldCloseT := t.gracefulCloseLocked()
Copy link
Member

Choose a reason for hiding this comment

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

Can you do this in t.goAwayActiveStreams() to avoid the duplication below?

if upperLimit == 0 { // This is the first GoAway Frame.
upperLimit = math.MaxUint32 // Kill all streams after the GoAway ID.
}
for k, v := range t.activeStreams {
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

for id, s := range t.activeStreams {

t.mu.Unlock()
if active == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

If there are no active streams, can we close and return above the select, even? Or do we care about the GOAWAY even though there are no streams?

Copy link
Member

Choose a reason for hiding this comment

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

As discussed, don't bother with this.

@dfawley dfawley merged commit aa5b2f7 into grpc:master Jul 28, 2017
@dfawley dfawley modified the milestone: 1.6 Release Aug 28, 2017
@MakMukhi MakMukhi deleted the goaway_client branch May 4, 2018 02:04
@lock lock bot locked as resolved and limited conversation to collaborators Oct 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants