Skip to content

[test] Fix race condition when accessing command buffer output#447

Merged
cendhu merged 1 commit intohyperledger:mainfrom
liran-funaro:buffer-race
Mar 19, 2026
Merged

[test] Fix race condition when accessing command buffer output#447
cendhu merged 1 commit intohyperledger:mainfrom
liran-funaro:buffer-race

Conversation

@liran-funaro
Copy link
Copy Markdown
Contributor

Type of change

  • Bug fix
  • Test update

Description

Root cause: The test was experiencing a race condition when accessing command output buffers. In UnitTestRunner, the command execution runs in a goroutine that continuously writes output to bytes.Buffer instances (cmdStdOut and cmdStdErr), while simultaneously another goroutine in assert.Eventually reads from these buffers via cmdStdOut.String() to check for expected output. Since bytes.Buffer is not thread-safe for concurrent read/write operations, this caused data races detected by the race detector when multiple goroutines accessed the buffer simultaneously.

Related issues

Signed-off-by: Liran Funaro <liran.funaro@gmail.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 90.389% (+0.1%) from 90.284%
when pulling a91b370 on liran-funaro:buffer-race
into 355e2a9 on hyperledger:main.

Copy link
Copy Markdown
Contributor

@cendhu cendhu left a comment

Choose a reason for hiding this comment

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

LGTM

@cendhu cendhu merged commit 00527a0 into hyperledger:main Mar 19, 2026
17 checks passed
@liran-funaro liran-funaro deleted the buffer-race branch March 19, 2026 09:03
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.

3 participants