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

Fix racey TestAttachAfterDetach #10200

Merged
merged 1 commit into from
Jan 21, 2015

Conversation

cpuguy83
Copy link
Member

No description provided.

@jessfraz
Copy link
Contributor

LGTM

@jessfraz
Copy link
Contributor

fixes race locally for me

if err != nil {
t.Fatalf("prompt read failed: %v", err)
select {
case err := <-readErr:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we wait for this in this select? Isn't it better to leave only <-cmdErr branch?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess technically if there was a read error, the string.Contains would fail.
Is that what you are getting at?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I mean that your test is not deterministic, because you can get signal through readErr or cmdErr and in branch about cmdErr you read readErr anyway, so why we need to wait on readErr concurrently with cmdErr if process is still expected to finish.

Copy link
Member Author

Choose a reason for hiding this comment

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

Even better, no more select.

Copy link
Member Author

Choose a reason for hiding this comment

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

meh, maybe I can't do that without select (and make sure the test doesn't hang)

@cpuguy83 cpuguy83 force-pushed the fix_racey_TestAttachAfterDetach branch 3 times, most recently from 6441cf0 to 26bf5fe Compare January 21, 2015 03:13
@cpuguy83
Copy link
Member Author

@LK4D4 Updated.

}

if !strings.Contains(string(bytes[:n]), "/ #") {
t.Fatalf("failed to get a new prompt. got %s", string(bytes[:n]))
if err := <-cmdErr; err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

lol, I'm pretty sure that this is equivalent of cmd.Wait :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I need to stop doing this stuff at night!

@tonistiigi
Copy link
Member

@cpuguy83 Thank you for fixing the race! The slight problem with this fix is that it doesn't fail cleanly if tested against the bug it was first created for(commits between #9511 - #10079). The second attach process is just closed then and this blocks the pty.Read leaving the test just hanging. I think it would be better to read in a goroutine and use select to detect which ends first. If process dies first then the test should fail.

@cpuguy83
Copy link
Member Author

@tonistiigi That's what I was doing, but I assumed (I guess falsely) that read would not actually block here. I'll update.

@tonistiigi
Copy link
Member

@cpuguy83 I think the real issue for the blocking is that one is supposed to close the tty after calling cmd.Start. https://github.com/kr/pty/blob/05017fcccf23c823bfdea560dcc958a136e54fb7/run.go#L17

I get a fail with read /dev/ptmx: input/output error after adding that.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
@cpuguy83
Copy link
Member Author

@tonistiigi Ah yep. Ok, this is fixed.
@LK4D4 your's too.

@cpuguy83 cpuguy83 force-pushed the fix_racey_TestAttachAfterDetach branch from 26bf5fe to 6ef8057 Compare January 21, 2015 15:11
@LK4D4
Copy link
Contributor

LK4D4 commented Jan 21, 2015

LGTM

LK4D4 added a commit that referenced this pull request Jan 21, 2015
@LK4D4 LK4D4 merged commit f72bcd3 into moby:master Jan 21, 2015
@cpuguy83 cpuguy83 deleted the fix_racey_TestAttachAfterDetach branch January 21, 2015 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants