Skip to content

Commit 941ebec

Browse files
authored
Fix typo increase counter on connection close instead of decreasing it (#1494)
1 parent b14c478 commit 941ebec

4 files changed

Lines changed: 82 additions & 5 deletions

File tree

  • runtime/binding-tcp/src
  • specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/streams/application/rfc793/max.connections.reset

runtime/binding-tcp/src/main/java/io/aklivity/zilla/runtime/binding/tcp/internal/stream/TcpClientRouter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public void detach(
194194

195195
public void close()
196196
{
197-
capacity.decrementAndGet();
197+
capacity.incrementAndGet();
198198
}
199199

200200
@Override

runtime/binding-tcp/src/test/java/io/aklivity/zilla/runtime/binding/tcp/internal/streams/ClientIT.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.rules.RuleChain.outerRule;
2323

24+
import java.io.IOException;
2425
import java.net.InetAddress;
2526
import java.net.InetSocketAddress;
2627
import java.net.UnknownHostException;
2728
import java.nio.ByteBuffer;
29+
import java.nio.channels.SelectionKey;
30+
import java.nio.channels.Selector;
2831
import java.nio.channels.ServerSocketChannel;
2932
import java.nio.channels.SocketChannel;
3033

@@ -352,21 +355,61 @@ public void shouldWriteDataAfterReceiveEnd() throws Exception
352355
value = "2")
353356
public void shouldResetWhenConnectionsExceeded() throws Exception
354357
{
355-
try (ServerSocketChannel server = ServerSocketChannel.open())
358+
try (ServerSocketChannel server = ServerSocketChannel.open();
359+
Selector selector = Selector.open())
356360
{
361+
server.configureBlocking(false);
357362
server.setOption(SO_REUSEADDR, true);
358363
server.bind(new InetSocketAddress("127.0.0.1", 12345));
364+
server.register(selector, SelectionKey.OP_ACCEPT);
359365

360366
k3po.start();
361367

362-
for (int i = 1; i < 3; i++)
368+
AcceptHandler handler = channel ->
369+
{
370+
channel.configureBlocking(true);
371+
channel.close();
372+
};
373+
374+
int accepted = 0;
375+
while (accepted < 2)
363376
{
364-
try (SocketChannel channel = server.accept())
377+
selector.select();
378+
for (SelectionKey key : selector.selectedKeys())
379+
{
380+
if (key.isAcceptable())
381+
{
382+
SocketChannel client = server.accept();
383+
handler.handle(client);
384+
accepted++;
385+
}
386+
}
387+
388+
if (accepted == 2)
365389
{
366-
k3po.notifyBarrier("CONNECTION_ACCEPTED_" + i);
390+
k3po.notifyBarrier("CONNECTION_ACCEPTED_1");
391+
k3po.notifyBarrier("CONNECTION_ACCEPTED_2");
367392
}
368393
}
369394

395+
accepted = 0;
396+
while (accepted < 2)
397+
{
398+
selector.select();
399+
for (SelectionKey key : selector.selectedKeys())
400+
{
401+
if (key.isAcceptable())
402+
{
403+
SocketChannel client = server.accept();
404+
handler.handle(client);
405+
accepted++;
406+
}
407+
}
408+
}
409+
410+
assert accepted == 2;
411+
412+
selector.selectedKeys().clear();
370413
k3po.finish();
371414
}
372415
}
@@ -376,4 +419,10 @@ public static InetAddress[] resolveHost(
376419
{
377420
throw new UnknownHostException();
378421
}
422+
423+
@FunctionalInterface
424+
interface AcceptHandler
425+
{
426+
void handle(SocketChannel channel) throws IOException;
427+
}
379428
}

specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/streams/application/rfc793/max.connections.reset/client.rpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,25 @@ write await CONNECTION_ACCEPTED_2
3030
write close
3131
read closed
3232

33+
read notify CONNECTION_CLOSED_2
34+
3335
connect "zilla://streams/app0"
3436
option zilla:window 8192
3537
option zilla:transmission "duplex"
3638
connect aborted
39+
40+
connect await CONNECTION_CLOSED_2
41+
"zilla://streams/app0"
42+
option zilla:window 8192
43+
option zilla:transmission "duplex"
44+
connected
45+
write close
46+
read closed
47+
48+
connect await CONNECTION_CLOSED_2
49+
"zilla://streams/app0"
50+
option zilla:window 8192
51+
option zilla:transmission "duplex"
52+
connected
53+
write close
54+
read closed

specs/binding-tcp.spec/src/main/scripts/io/aklivity/zilla/specs/binding/tcp/streams/application/rfc793/max.connections.reset/server.rpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ write close
3535
write notify CLOSED
3636

3737
rejected
38+
39+
accepted
40+
connected
41+
read closed
42+
write close
43+
44+
accepted
45+
connected
46+
read closed
47+
write close

0 commit comments

Comments
 (0)