Skip to content

Commit cec6932

Browse files
committed
Prevent spurious concurrency related errors
1 parent 13727fe commit cec6932

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

btrace-agent/src/main/java/org/openjdk/btrace/agent/RemoteClient.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ public void onCommand(Command cmd) throws IOException {
237237
try {
238238
boolean isConnected = true;
239239
try {
240-
output.reset();
240+
synchronized (output) {
241+
output.reset();
242+
}
241243
} catch (SocketException e) {
242244
isConnected = false;
243245
}
@@ -285,9 +287,11 @@ private boolean dispatchCommand(Command cmd, boolean isConnected) {
285287
{
286288
((DisconnectCommand) cmd).setProbeId(id.toString());
287289
if (output != null) {
288-
WireIO.write(output, cmd);
289-
output.flush();
290-
output.close();
290+
synchronized (output) {
291+
WireIO.write(output, cmd);
292+
output.flush();
293+
output.close();
294+
}
291295
oosUpdater.compareAndSet(this, output, null);
292296
}
293297
if (input != null) {
@@ -327,7 +331,9 @@ protected void closeAll() throws IOException {
327331

328332
ObjectOutputStream output = oos;
329333
if (output != null) {
330-
output.close();
334+
synchronized (output) {
335+
output.close();
336+
}
331337
oosUpdater.compareAndSet(this, output, null);
332338
}
333339
ObjectInputStream input = ois;

0 commit comments

Comments
 (0)