Skip to content

Commit

Permalink
fix connectionId returned by follower session after disconnect
Browse files Browse the repository at this point in the history
Previously, it would return the old connectionId until next reconnect,
now it will return NO_CONNECTION_ID.
  • Loading branch information
wojciech-adaptive committed Aug 2, 2024
1 parent db9dd5a commit a8d4747
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,17 @@ public Action onDisconnect(
}
}

final WeakReference<SessionWriter> sessionWriterRef =
sessionIdToFollowerSessionWriter.get(session.id());
if (sessionWriterRef != null)
{
final SessionWriter sessionWriter = sessionWriterRef.get();
if (sessionWriter != null)
{
InternalSession.disconnectWriter(sessionWriter);
}
}

connectionIdToSession.remove(connectionId);

if (isEngineOwned)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ public void linkTo(final SessionWriter sessionWriter)
sessionWriter.linkTo(this);
}

public static void disconnectWriter(final SessionWriter writer)
{
writer.onDisconnect();
}

public static void closeWriter(final SessionWriter writer)
{
writer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import uk.co.real_logic.artio.protocol.GatewayPublication;
import uk.co.real_logic.artio.util.MutableAsciiBuffer;

import static uk.co.real_logic.artio.GatewayProcess.NO_CONNECTION_ID;
import static uk.co.real_logic.artio.messages.MessageStatus.OK;

/**
Expand Down Expand Up @@ -207,6 +208,11 @@ void linkTo(final InternalSession session)
this.connectionId = session.connectionId();
}

void onDisconnect()
{
connectionId = NO_CONNECTION_ID;
}

void checkState()
{
if (closed)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static uk.co.real_logic.artio.Constants.*;
import static uk.co.real_logic.artio.GatewayProcess.NO_CONNECTION_ID;
import static uk.co.real_logic.artio.MonitoringAgentFactory.consumeDistinctErrors;
import static uk.co.real_logic.artio.Reply.State.ERRORED;
import static uk.co.real_logic.artio.TestFixtures.launchMediaDriver;
Expand Down Expand Up @@ -988,6 +989,27 @@ private void resetSomeSequenceNumbersOfOfflineSessions(
assertAcceptingSessionHasSequenceIndex(retry ? 2 : 1);
}

@Test(timeout = TEST_TIMEOUT_IN_MS)
public void followerSessionShouldReturnCurrentConnectionId()
{
launch(this::nothing);

final SessionWriter followerSession = createFollowerSession(TEST_REPLY_TIMEOUT_IN_MS);
assertEquals(NO_CONNECTION_ID, followerSession.connectionId());

for (int i = 0; i < 2; i++)
{
connectPersistingSessions();

assertNotEquals(NO_CONNECTION_ID, followerSession.connectionId());
assertEquals(acceptingSession.connectionId(), followerSession.connectionId());

disconnectSessions();

assertEquals(NO_CONNECTION_ID, followerSession.connectionId());
}
}

private void connectPersistingSessions()
{
connectPersistingSessions(AUTOMATIC_INITIAL_SEQUENCE_NUMBER, false);
Expand Down

0 comments on commit a8d4747

Please sign in to comment.