Skip to content

Commit 1ca5d78

Browse files
committed
Fix race condition on concurrent capture_log, closes #12692
1 parent aab3543 commit 1ca5d78

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/ex_unit/lib/ex_unit/capture_server.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ defmodule ExUnit.CaptureServer do
232232

233233
for [string_io, level] <- :ets.match(@ets, {:_, :"$1", :"$2"}),
234234
:logger.compare_levels(event.level, level) in [:gt, :eq] do
235-
:ok = IO.write(string_io, chardata)
235+
# There is a race condition where the capture_log is removed
236+
# but another process is attempting to log to string io device
237+
# that no longer exists, so we wrap it in try/catch.
238+
try do
239+
IO.write(string_io, chardata)
240+
rescue
241+
_ -> :ok
242+
end
236243
end
237244
end
238245
end

0 commit comments

Comments
 (0)