Skip to content

Commit

Permalink
[JENKINS-36871] Remove excessive synchronization and rollback findbug…
Browse files Browse the repository at this point in the history
…s introduced bug

- We don't want to synchronize as that will cause issues during the close. We can rely on the stack for ensuring that reads are serialized and writes are serialized and the `channel` field is write once with the write guarded by the synchronized setup method
  • Loading branch information
stephenc committed Aug 11, 2016
1 parent 5566751 commit 926307a
Showing 1 changed file with 4 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract class AbstractByteBufferCommandTransport extends CommandTranspor
/**
* Our channel.
*/
protected Channel channel;
private Channel channel;
/**
* The chunk header buffer.
*/
Expand Down Expand Up @@ -133,7 +133,7 @@ public abstract class AbstractByteBufferCommandTransport extends CommandTranspor
* @throws IOException if something goes wrong during the receive.
* @throws InterruptedException if interrupted during the receive.
*/
public final synchronized void receive(@Nonnull ByteBuffer data) throws IOException, InterruptedException {
public final void receive(@Nonnull ByteBuffer data) throws IOException, InterruptedException {
while (receiver != null && readCommandIndex > 0) {
processCommand();
}
Expand Down Expand Up @@ -198,7 +198,6 @@ private void processCommand() throws IOException {
try {
FastByteBufferQueueInputStream is = new FastByteBufferQueueInputStream(receiveQueue, readCommandSizes[0]);
try {
final Channel channel = getChannel();
ObjectInputStreamEx ois = new ObjectInputStreamEx(is, channel.baseClassLoader, channel.classFilter);
receiver.handle(Command.readFrom(channel, ois));
} catch (IOException e1) {
Expand Down Expand Up @@ -256,7 +255,7 @@ public void setFrameSize(int transportFrameSize) {
* @return the channel.
*/
@Nullable // only null before setup.
private synchronized Channel getChannel() {
protected Channel getChannel() {
return channel;
}

Expand Down Expand Up @@ -286,7 +285,7 @@ public final void write(Command cmd, boolean last) throws IOException {
ByteBufferQueueOutputStream bqos = new ByteBufferQueueOutputStream(sendStaging);
ObjectOutputStream oos = new ObjectOutputStream(bqos);
try {
cmd.writeTo(getChannel(), oos);
cmd.writeTo(channel, oos);
} finally {
oos.close();
}
Expand Down

0 comments on commit 926307a

Please sign in to comment.