Skip to content

Commit

Permalink
More p2p http ref count fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Oct 7, 2024
1 parent 8fb1d05 commit 0290ddd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/main/java/org/peergos/protocol/http/HttpProtocol.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.peergos.protocol.http;

import io.ipfs.cid.*;
import io.ipfs.multibase.*;
import io.ipfs.multihash.*;
import io.libp2p.core.*;
import io.libp2p.core.multistream.*;
import io.libp2p.protocol.*;
Expand Down Expand Up @@ -48,9 +45,9 @@ public void onMessage(@NotNull Stream stream, FullHttpResponse msg) {
CompletableFuture<FullHttpResponse> req = queue.poll();
if (req != null) {
req.complete(msg.retain());
req.thenAccept(x -> msg.release());
} else
} else {
msg.release();
}
stream.close();
}

Expand Down Expand Up @@ -125,9 +122,7 @@ protected void initChannel(Channel ch) throws Exception {
fut.addListener(x -> {
if (x.isSuccess())
ch.writeAndFlush(retained).addListener(f -> {
if (!f.isSuccess()) {
retained.release();
}
retained.release();
});
else
retained.release();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/peergos/EmbeddedIpfsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void largeWrite() throws Exception {
.collect(Collectors.toList()), List.of(new MultiAddress("/ip4/127.0.0.1/tcp/" + TestPorts.getPort())), Optional.of(http2));
node2.start();

for (int i = 0; i < 100; i++) {
for (int i = 0; i < 1000; i++) {
ByteBuf largeBody = Unpooled.buffer(2 * 1024 * 1024);
DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/hey", largeBody);
HttpProtocol.HttpController http = node2.p2pHttp.get().dial(node2.node, node1.node.getPeerId(), node1.node.listenAddresses().toArray(Multiaddr[]::new))
Expand All @@ -94,6 +94,7 @@ public void largeWrite() throws Exception {
byte[] body = bout.toByteArray();
Assert.assertTrue("Correct response", Arrays.equals(body, replyBytes));
resp.release();
resp.release();
}

node1.stop();
Expand Down

0 comments on commit 0290ddd

Please sign in to comment.