Ask questionspotential goroutine leak caused by recv deadlock
<!-- If you are reporting a new issue, make sure that we do not have any duplicates already open. You can ensure this by searching the issue list for this repository. If there is a duplicate, please close your issue and add a comment to the existing issue instead.
If you suspect your issue is a bug, please edit your issue description to include the BUG REPORT INFORMATION shown below. If you fail to provide this information within 7 days, we cannot debug your issue and will close it. We will, however, reopen it if you later provide the information.
For more information about reporting issues, see https://github.com/moby/moby/blob/master/CONTRIBUTING.md#reporting-other-issues
The GitHub issue tracker is for bug reports and feature requests. General support for docker can be found at the following locations:
General support for moby can be found at the following locations:
Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST -->
<!-- Briefly describe the problem you are having in a few paragraphs. --> A infinite-loop with select has potential to be blocked at channel recv operation, which will cause a goroutine leak.
Steps to reproduce the issue: https://github.com/moby/moby/blob/627bbd3fa48b186170931404c9637ade9b854774/daemon/logger/awslogs/cloudwatchlogs_test.go#L715-L716 In TestCollectBatchMultilinePattern，a new goroutine been created https://github.com/moby/moby/blob/627bbd3fa48b186170931404c9637ade9b854774/daemon/logger/awslogs/cloudwatchlogs.go#L560-L609 Above loop will keep running and calling l.publishBatch https://github.com/moby/moby/blob/627bbd3fa48b186170931404c9637ade9b854774/daemon/logger/awslogs/cloudwatchlogs.go#L681-L687
l.putLogEvents will be called
Since it is in test, the mock client is given. However, in test
TestCollectBatchMultilinePattern, there is no action to close m.putLogEventsResult or notify PutLogEvents, so
output := <-m.putLogEventsResult will be blocked. This will cause the goroutine created by
go stream.collectBatch(d) deadlock.
Describe the results you received: A goroutine leak caused by blocked channel recv.
Describe the results you expected: Proper release goroutine.
Additional information you deem important (e.g. issue happens only occasionally):
(paste your output here)
(paste your output here)
Additional environment details (AWS, VirtualBox, physical, etc.):
Answer questions system-pclub
Only one message is sent to mockClient.putLogEventsResult in TestCollectBatchMultilinePattern() (https://github.com/moby/moby/blob/master/daemon/logger/awslogs/cloudwatchlogs_test.go#L700)
If the loop in function collectBatch() (https://github.com/moby/moby/blob/master/daemon/logger/awslogs/cloudwatchlogs.go#L562) chooses ticker.C more than once, function PutLogEvents() (https://github.com/moby/moby/blob/master/daemon/logger/awslogs/cwlogsiface_mock_test.go#L76) will be called more than once.
At this time, the receiving operation on m.putLogEventsResult in function PutLogEvents() will block the child goroutine created by "go stream.collectBatch()" in TestCollectBatchMultilinePattern() forever.
Basically, a deadlock is triggered.