Skip to content

merge #1

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

Merged
merged 7 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# Changelog
## [0.29.2](https://github.com/osheroff/mysql-binlog-connector-java/compare/0.29.2...0.29.1) - 2024-04-22

- avoid SSL deadlocks using opt-in SO_LINGER with value of 0

## [0.29.1] - 2024-03-24

- bug fixes for VERY long transactions

## [0.29.0](https://github.com/osheroff/mysql-binlog-connector-java/compare/0.29.0...0.28.3) - 2023-11-29

- add support for mysql8 specific metadata
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.zendesk</groupId>
<artifactId>mysql-binlog-connector-java</artifactId>
<version>0.29.0</version>
<version>0.29.2</version>

<name>mysql-binlog-connector-java</name>
<description>MySQL Binary Log connector</description>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public X509Certificate[] getAcceptedIssuers() {
private volatile long binlogPosition = 4;
private volatile long connectionId;
private SSLMode sslMode = SSLMode.DISABLED;
private boolean useNonGracefulDisconnect = false;

protected GtidSet gtidSet;
protected final Object gtidSetAccessLock = new Object();
Expand Down Expand Up @@ -249,6 +250,10 @@ public void setSSLMode(SSLMode sslMode) {
this.sslMode = sslMode;
}

public void setUseNonGracefulDisconnect(boolean useNonGracefulDisconnect) {
this.useNonGracefulDisconnect = useNonGracefulDisconnect;
}

public long getMasterServerId() {
return this.masterServerId;
}
Expand Down Expand Up @@ -891,7 +896,7 @@ public void run() {
if (connectionLost) {
logger.info("Keepalive: Trying to restore lost connection to " + hostname + ":" + port);
try {
terminateConnect();
terminateConnect(useNonGracefulDisconnect);
connect(connectTimeout);
} catch (Exception ce) {
logger.warning("keepalive: Failed to restore connection to " + hostname + ":" + port +
Expand Down Expand Up @@ -1341,8 +1346,11 @@ private static boolean awaitTerminationInterruptibly(ExecutorService executorSer
}

private void terminateConnect() throws IOException {
terminateConnect(false);
}
private void terminateConnect(boolean force) throws IOException {
do {
disconnectChannel();
disconnectChannel(force);
} while (!tryLockInterruptibly(connectLock, 1000, TimeUnit.MILLISECONDS));
connectLock.unlock();
}
Expand All @@ -1356,8 +1364,14 @@ private static boolean tryLockInterruptibly(Lock lock, long time, TimeUnit unit)
}

private void disconnectChannel() throws IOException {
disconnectChannel(false);
}
private void disconnectChannel(boolean force) throws IOException {
connected = false;
if (channel != null && channel.isOpen()) {
if (force) {
channel.setShouldUseSoLinger0();
}
channel.close();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public GtidEventData deserialize(ByteArrayInputStream inputStream) throws IOExce
}
// Total transaction length (including this GTIDEvent), introduced in MySQL-8.0.2
if (inputStream.available() >= TRANSACTION_LENGTH_MIN_LENGTH) {
transactionLength = inputStream.readPackedInteger();
transactionLength = inputStream.readPackedLong();
}
immediateServerVersion = UNDEFINED_SERVER_VERSION;
originalServerVersion = UNDEFINED_SERVER_VERSION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public int readPackedInteger() throws IOException {
return number.intValue();
}

/**
* @see #readPackedNumber()
* @throws IOException in case of malformed number, eof, null
* @return long
*/
public long readPackedLong() throws IOException {
Number number = readPackedNumber();
if (number == null) {
throw new IOException("Unexpected NULL where long should have been");
}
return number.longValue();
}

/**
* Format (first-byte-based):<br>
* 0-250 - The first byte is the number (in the range 0-250). No additional bytes are used.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.nio.channels.Channel;

/**
Expand All @@ -38,6 +39,7 @@ public class PacketChannel implements Channel {
private Socket socket;
private ByteArrayInputStream inputStream;
private ByteArrayOutputStream outputStream;
private boolean shouldUseSoLinger0 = false;

public PacketChannel(String hostname, int port) throws IOException {
this(new Socket(hostname, port));
Expand Down Expand Up @@ -109,6 +111,10 @@ public boolean isSSL() {
return isSSL;
}

public void setShouldUseSoLinger0() {
shouldUseSoLinger0 = true;
}

@Override
public boolean isOpen() {
return !socket.isClosed();
Expand All @@ -126,6 +132,14 @@ public void close() throws IOException {
} catch (Exception e) {
// ignore
}
if (shouldUseSoLinger0) {
try {
socket.setSoLinger(true, 0);
} catch (SocketException e) {
// ignore
}
}
socket.close();
shouldUseSoLinger0 = false;
}
}