Skip to content
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

[okex-stream] all login-required channels become invalid after a network disconnection and reconnection #4968

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ public class OkexStreamingService extends JsonNettyStreamingService {

private final ExchangeSpecification xSpec;

private volatile boolean loginDone = false;

private volatile boolean needToResubscribeChannels = false;

public OkexStreamingService(String apiUrl, ExchangeSpecification exchangeSpecification) {
super(apiUrl);
this.xSpec = exchangeSpecification;
}

@Override
public Completable connect() {
loginDone = xSpec.getApiKey() == null;
Completable conn = super.connect();
return conn.andThen(
(CompletableSource)
Expand All @@ -82,6 +87,14 @@ public Completable connect() {
});
}

@Override
public void resubscribeChannels() {
needToResubscribeChannels = true;
if (loginDone) {
super.resubscribeChannels();
}
}

public void login() throws JsonProcessingException {
Mac mac;
try {
Expand Down Expand Up @@ -123,6 +136,18 @@ public void messageHandler(String message) {
LOG.error("Error parsing incoming message to JSON: {}", message);
return;
}
// Retry after a successful login
if (jsonNode.has("event")) {
String event = jsonNode.get("event").asText();
if ("login".equals(event)) {
loginDone = true;
if (needToResubscribeChannels) {
this.resubscribeChannels();
needToResubscribeChannels = false;
}
return;
}
}

if (processArrayMessageSeparately() && jsonNode.isArray()) {
// In case of array - handle every message separately.
Expand Down Expand Up @@ -227,4 +252,4 @@ public void pingPongDisconnectIfConnected() {
pingPongSubscription.dispose();
}
}
}
}
Loading