Skip to content

Commit 63509bb

Browse files
authored
resolves #215 fix watchdog race condition leading to ThreadError(<killed thread>) on JRuby (#216)
1 parent b014e77 commit 63509bb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
This document provides a high-level view of the changes to the {project-name} by release.
66
For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
77

8+
== Unreleased
9+
10+
* fix watchdog race condition leading to `ThreadError(<killed thread>)` on JRuby ({uri-repo}/pull/215[#215])
11+
812
== 2.0.0.rc2 (2021-01-07) - @slonopotamus
913

1014
* Fix release workflow

lib/pygments/popen.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,17 @@ def highlight(code, opts = {})
227227
def with_watchdog(timeout_time, error_message)
228228
state_mutex = Mutex.new
229229
state = :alive
230+
wd_cleanup = ConditionVariable.new
230231

231232
watchdog = timeout_time > 0 ? Thread.new do
232233
state_mutex.synchronize do
233-
state_mutex.sleep(timeout_time) if state != :finished
234+
wd_cleanup.wait(state_mutex, timeout_time) if state != :finished
234235
if state != :finished
235236
@log.error error_message
236237
stop error_message
237238
state = :timeout
238239
end
240+
239241
end
240242
end : nil
241243
begin
@@ -244,7 +246,8 @@ def with_watchdog(timeout_time, error_message)
244246
if watchdog
245247
state_mutex.synchronize do
246248
state = :finished if state == :alive
247-
watchdog.wakeup if watchdog.alive?
249+
# wake up watchdog thread
250+
wd_cleanup.signal
248251
end
249252
watchdog.join
250253
end

0 commit comments

Comments
 (0)