Skip to content

fix descriptor leak #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/org/tarantool/TarantoolClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;


public class TarantoolClientImpl extends TarantoolBase<Future<List<?>>> implements TarantoolClient {
public static final CommunicationException NOT_INIT_EXCEPTION = new CommunicationException("Not connected, initializing connection");
protected TarantoolClientConfig config;
Expand Down Expand Up @@ -116,8 +115,8 @@ protected void reconnect(int retry, Throwable lastError) {
}

protected void connect(final SocketChannel channel) throws Exception {
DataInputStream is = new DataInputStream(cis = new ByteBufferInputStream(channel));
try {
DataInputStream is = new DataInputStream(cis = new ByteBufferInputStream(channel));
byte[] bytes = new byte[64];
is.readFully(bytes);
String firstLine = new String(bytes);
Expand All @@ -132,20 +131,22 @@ protected void connect(final SocketChannel channel) throws Exception {
readPacket(is);
Long code = (Long) headers.get(Key.CODE.getId());
if (code != 0) {
is.close();
throw serverError(code, body.get(Key.ERROR.getId()));
}
}
this.is = is;
} catch (IOException e) {
try {
is.close();
if (null != is)
is.close();
} catch (IOException ignored) {

}
try {
cis.close();
if (null != cis)
cis.close();
} catch (IOException ignored) {

}
throw new CommunicationException("Couldn't connect to tarantool", e);
}
Expand Down Expand Up @@ -426,9 +427,11 @@ protected void writeFully(SocketChannel channel, ByteBuffer buffer) throws IOExc

@Override
public void close() {

if (connector != null) {
connector.interrupt();
}

stopIO();
}

Expand Down