Skip to content

Commit

Permalink
Do not require BackendKeyData (impossibl#424)
Browse files Browse the repository at this point in the history
Some databases, such as CockroachDB, do not send BackendKeyData on
connection initialization. Previously, the ServerConnectionFactory would
assume that BackendKeyData would always be present which caused a
NullPointerException. Now, the BackendKeyData defaults to 0 instead of
null.

If the BackendKeyData is not set, then the CancelRequestTask
short-circuits and logs a warning.
  • Loading branch information
rafiss committed Aug 14, 2019
1 parent 239d492 commit 94b2463
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
import java.net.Socket;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.util.logging.Logger;

import io.netty.channel.unix.DomainSocketAddress;

public class CancelRequestTask extends ExecutionTimerTask {

private static final Logger logger = Logger.getLogger(CancelRequestTask.class.getName());

private SocketAddress serverAddress;
private ServerConnection.KeyData keyData;

Expand All @@ -64,6 +67,11 @@ public void go() {

private void sendCancelRequest() {

if (keyData.getProcessId() == 0 && keyData.getSecretKey() == 0) {
logger.warning("Cannot send CancelRequest because of missing BackendKeyData.");
return;
}

try {

if (serverAddress instanceof InetSocketAddress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public void handleNegotiate(Version maxProtocolVersion, List<String> unrecognize
}

@Override
public void handleComplete(Integer processId, Integer secretKey, Map<String, String> parameterStatuses, List<Notice> notices) {
public void handleComplete(int processId, int secretKey, Map<String, String> parameterStatuses, List<Notice> notices) {

startupParameterStatuses.putAll(parameterStatuses);
startupKeyData.set(new KeyData(processId, secretKey));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ interface CompletionHandler {

void handleNegotiate(Version maxProtocolVersion, List<String> unrecognizedParameters) throws IOException;

void handleComplete(Integer processId, Integer secretKey, Map<String, String> parameterStatuses, List<Notice> notices) throws IOException;
void handleComplete(int processId, int secretKey, Map<String, String> parameterStatuses, List<Notice> notices) throws IOException;
void handleError(Throwable cause, List<Notice> notices) throws IOException;

}

private Version protocolVersion;
private Map<String, Object> startupParameters;
private CompletionHandler handler;
private Integer backendProcessId;
private Integer backendSecretKey;
private int backendProcessId;
private int backendSecretKey;
private Map<String, String> parameterStatuses;
private List<Notice> notices;

Expand Down

0 comments on commit 94b2463

Please sign in to comment.