Skip stop if keepalive is already in stopping state
In current design, crash has been generated when stop function
has been re-entered to catch unexpected behavior. However,
it is possible to re-enter stop function if the network
disconnection occurs after stopping.
Thus, skip stop if keepalive is already in stopping state.
Test: atest ConnectivityServiceTest#testNattSocketKeepalives \
--rerun-until-failure 60000
Bug: 167332570
Change-Id: Ic7068ad3dc990e957c37b8d87d48ebb6469b101f
This commit is contained in:
@@ -4292,6 +4292,32 @@ public class ConnectivityServiceTest {
|
||||
myNet = connectKeepaliveNetwork(lp);
|
||||
mWiFiNetworkAgent.setStartKeepaliveEvent(SocketKeepalive.SUCCESS);
|
||||
|
||||
// Check that a stop followed by network disconnects does not result in crash.
|
||||
try (SocketKeepalive ka = mCm.createSocketKeepalive(
|
||||
myNet, testSocket, myIPv4, dstIPv4, executor, callback)) {
|
||||
ka.start(validKaInterval);
|
||||
callback.expectStarted();
|
||||
// Delay the response of keepalive events in networkAgent long enough to make sure
|
||||
// the follow-up network disconnection will be processed first.
|
||||
mWiFiNetworkAgent.setKeepaliveResponseDelay(3 * TIMEOUT_MS);
|
||||
ka.stop();
|
||||
|
||||
// Make sure the stop has been processed. Wait for executor idle is needed to prevent
|
||||
// flaky since the actual stop call to the service is delegated to executor thread.
|
||||
waitForIdleSerialExecutor(executor, TIMEOUT_MS);
|
||||
waitForIdle();
|
||||
|
||||
mWiFiNetworkAgent.disconnect();
|
||||
mWiFiNetworkAgent.expectDisconnected();
|
||||
callback.expectStopped();
|
||||
callback.assertNoCallback();
|
||||
}
|
||||
|
||||
// Reconnect.
|
||||
waitForIdle();
|
||||
myNet = connectKeepaliveNetwork(lp);
|
||||
mWiFiNetworkAgent.setStartKeepaliveEvent(SocketKeepalive.SUCCESS);
|
||||
|
||||
// Check that keepalive slots start from 1 and increment. The first one gets slot 1.
|
||||
mWiFiNetworkAgent.setExpectedKeepaliveSlot(1);
|
||||
int srcPort2 = 0;
|
||||
|
||||
Reference in New Issue
Block a user