Skip to content

Commit 7c18d9f

Browse files
committed
fix #4201: jetty's bytebuffers may be immediately re-used
1 parent 387237b commit 7c18d9f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

httpclient-jetty/src/main/java/io/fabric8/kubernetes/client/jetty/JettyAsyncResponseListener.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,20 @@ public void onContent(Response response, LongConsumer demand, ByteBuffer content
9494
this.demand.complete(demand);
9595
}
9696
try {
97-
bodyConsumer.consume(process(response, content), this);
97+
// we must clone as the buffer can be reused after the call to succeeded
98+
bodyConsumer.consume(process(response, clone(content)), this);
9899
callback.succeeded();
99100
} catch (Exception e) {
100101
callback.failed(e);
101102
}
102103
}
103104

104105
protected abstract T process(Response response, ByteBuffer content);
106+
107+
public static ByteBuffer clone(ByteBuffer original) {
108+
ByteBuffer clone = ByteBuffer.allocate(original.remaining());
109+
clone.put(original);
110+
clone.flip();
111+
return clone;
112+
}
105113
}

0 commit comments

Comments
 (0)