Skip to content

Commit 0bfff3a

Browse files
committed
DAP: use Mutex when sending response
When debug.gem tries to send response from multiple threads, the socket connection is closed. I confirmed this bug when using custom request from vscode-rdbg
1 parent 733dd4b commit 0bfff3a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/debug/server_dap.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def self.local_fs_map_set map
125125
def dap_setup bytes
126126
CONFIG.set_config no_color: true
127127
@seq = 0
128+
@send_lock = Mutex.new
128129

129130
case self
130131
when UI_UnixDomainServer
@@ -212,9 +213,13 @@ def send **kw
212213
if sock = @sock
213214
kw[:seq] = @seq += 1
214215
str = JSON.dump(kw)
215-
sock.write "Content-Length: #{str.bytesize}\r\n\r\n#{str}"
216+
@send_lock.synchronize do
217+
sock.write "Content-Length: #{str.bytesize}\r\n\r\n#{str}"
218+
end
216219
show_protocol '<', str
217220
end
221+
rescue Errno::EPIPE => e
222+
$stderr.puts "#{e.inspect} rescued during sending message"
218223
end
219224

220225
def send_response req, success: true, message: nil, **kw

test/support/protocol_test_case.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,4 +1065,3 @@ def parse_ k, v
10651065
end
10661066
end
10671067
end
1068-

0 commit comments

Comments
 (0)