Skip to content

Commit

Permalink
- Backend buffer drain fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjzazuet committed Sep 1, 2024
1 parent 780b877 commit 3e1a0ae
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
8 changes: 1 addition & 7 deletions a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpIo.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public A4TcpIo(SelectionKey channelKey, SocketChannel rawChannel) {
this.channelKey = Objects.requireNonNull(channelKey);
this.id = this.channel.socket().toString();
this.bufferSize = rawChannel.socket().getReceiveBufferSize();
allocateBuffer();
} catch (Exception e) {
throw new IllegalStateException("Client-Server channel initialization error - " + rawChannel.socket(), e);
}
Expand All @@ -53,16 +52,11 @@ public A4TcpIo(InetSocketAddress dest, Selector selector, boolean openTls, Execu
this.channelKey = chn.register(selector, SelectionKey.OP_READ);
this.id = channel.socket().toString();
this.bufferSize = chn.socket().getReceiveBufferSize();
allocateBuffer();
} catch (Exception e) {
throw new IllegalStateException("Server-Backend channel initialization error - " + dest, e);
}
}

private void allocateBuffer() {
bufferPool.offer(ByteBuffer.allocateDirect(bufferSize));
}

private ByteBuffer getBuffer() {
ByteBuffer buffer = bufferPool.poll();
if (buffer == null) {
Expand Down Expand Up @@ -127,7 +121,7 @@ public SocketChannel getRawChannel() {
? ((SSLSocketChannel) c).getWrappedSocketChannel().socket()
: c.socket();
return format(
"[%s, bq%02d, bp%02d, %02d, %02d, %s %s %s]",
"[%s, bq%02d, bp%02d, i%02d, r%02d, %s %s %s]",
format("%s%s%s%s",
k.isReadable() ? "r" : "",
k.isWritable() ? "w" : "",
Expand Down
3 changes: 3 additions & 0 deletions a4-core/src/main/java/io/vacco/a4lb/tcp/A4TcpSess.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ private void tcpUpdate(SelectionKey key) {
}
} else if (bytes == 0 && tlsClient) {
initBackend();
} else if (bytes == -1 && isBk && !backend.bufferQueue.isEmpty()) {
client.channelKey.interestOps(SelectionKey.OP_WRITE);
backend.channelKey.interestOps(0);
} else if (bytes == -1) {
tearDown(null);
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins { id("io.vacco.oss.gitflow") version "1.0.1" apply(false) }
subprojects {
apply(plugin = "io.vacco.oss.gitflow")
group = "io.vacco.awe4lb"
version = "0.2.0"
version = "0.2.1"

configure<io.vacco.oss.gitflow.GsPluginProfileExtension> {
addClasspathHell()
Expand Down

0 comments on commit 3e1a0ae

Please sign in to comment.