Skip to content

awslogs: Fix a race in mockcwlogsclient#22985

Merged
crosbymichael merged 1 commit intomoby:masterfrom
samuelkarp:awslogs-logging-driver
May 25, 2016
Merged

awslogs: Fix a race in mockcwlogsclient#22985
crosbymichael merged 1 commit intomoby:masterfrom
samuelkarp:awslogs-logging-driver

Conversation

@samuelkarp
Copy link
Member

@samuelkarp samuelkarp commented May 25, 2016

- What I did
Fixed a race found in #22963 differently than #22971

- How I did it
Copy the LogEvents slice in mockcwlogsclient.PutLogEvents since the tests may read through the slice asynchronously

- How to verify it
TESTDIRS=daemon/logger/awslogs BUILDFLAGS=-race TESTFLAGS="-test.count 100" make test-unit

Closes #22971

@GordonTheTurtle GordonTheTurtle added status/0-triage dco/no Automatically set by a bot when one of the commits lacks proper signature labels May 25, 2016
@samuelkarp samuelkarp force-pushed the awslogs-logging-driver branch from f0d8884 to 1544ac6 Compare May 25, 2016 17:32
@GordonTheTurtle GordonTheTurtle removed the dco/no Automatically set by a bot when one of the commits lacks proper signature label May 25, 2016
@LK4D4
Copy link
Contributor

LK4D4 commented May 25, 2016

Is that race is real for a real client? Because I think it's pretty the same as copy and even slightly worse, because not preallocating anything :(

@samuelkarp
Copy link
Member Author

@LK4D4 I'm not sure there's really a race in the driver as opposed to the test, but this does avoid a (potentially large) copy. To answer your question on #22971, PutLogEvents is indeed a blocking call.

Preallocation can be changed, but what I have now is fairly similar behavior to the truncation that was already occurring.

@LK4D4
Copy link
Contributor

LK4D4 commented May 25, 2016

If it's blocking then let's make mockClient blocking and avoid allocations at all :)

@samuelkarp
Copy link
Member Author

@LK4D4 Making mockClient block doesn't seem to make the race detector happy by itself. I'm not sure exactly what the race detector is unhappy about; the slice element contents are never modified concurrently and the PutLogEventsInput struct gets an independent copy of the slice header. The only modification of the slice itself happens with sort.Sort, but nothing is concurrently modifying the slice during that operation.

@LK4D4
Copy link
Contributor

LK4D4 commented May 25, 2016

@samuelkarp could you post race detector output pls?
And patch for blocking mockClient

@samuelkarp
Copy link
Member Author

samuelkarp@21a5189 shows the mockClient with zero-length channels so that it blocks. Race detector output is here.

@LK4D4
Copy link
Contributor

LK4D4 commented May 25, 2016

Ok, mockClient code is confusing, but as I understand issue we need to make copy of events inside func (m *mockcwlogsclient) PutLogEvents( or test itself will mess with events after this call returns (it returns because we're sending result in channel at the beginning)

@samuelkarp
Copy link
Member Author

@LK4D4 That seems to work too. I'll update this PR with that change.

@samuelkarp
Copy link
Member Author

(Also, if Docker has picked a mock generation tool, I'd be happy to switch away from this confusing, hand-written mock.)

Signed-off-by: Samuel Karp <skarp@amazon.com>
@samuelkarp samuelkarp force-pushed the awslogs-logging-driver branch from 1544ac6 to c1ad02c Compare May 25, 2016 18:51
@samuelkarp samuelkarp changed the title awslogs: Fix a race in collectBatch() awslogs: Fix a race in mockcwlogsclient May 25, 2016
@samuelkarp
Copy link
Member Author

@LK4D4 PTAL

@LK4D4
Copy link
Contributor

LK4D4 commented May 25, 2016

LGTM

1 similar comment
@crosbymichael
Copy link
Contributor

LGTM

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.

4 participants