@@ -1172,6 +1172,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
11721172 return nullptr ;
11731173 }
11741174
1175+ const auto attemptNr_capture = transactionFront->getStartSync ().getAttemptNr ();
11751176 transactionFront->getStartSync ().advanceAttemptNr ();
11761177 transactionFront->getStartSync ().setAttemptTime (model.getClock ().now ());
11771178 transactionFront->commit ();
@@ -1203,6 +1204,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12031204 }
12041205 });
12051206
1207+ #if MO_TX_ATTEMPT_TIMEOUT == 0
1208+ // a timeout should not increase the attemptNr. Roll back to previous attemptNr
1209+ startTx->setOnTimeoutListener ([transactionFront_capture, attemptNr_capture] () {
1210+ MO_DBG_DEBUG (" StartTx timeout -> roll back attemptNr and try again" );
1211+ if (transactionFront_capture) {
1212+ transactionFront_capture->getStartSync ().setAttemptNr (attemptNr_capture);
1213+ transactionFront_capture->commit ();
1214+ }
1215+ });
1216+ #else
1217+ (void )attemptNr_capture;
1218+ #endif
1219+
12061220 return startTx;
12071221 }
12081222
@@ -1229,6 +1243,7 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12291243 return nullptr ;
12301244 }
12311245
1246+ const auto attemptNr_capture = transactionFront->getStopSync ().getAttemptNr ();
12321247 transactionFront->getStopSync ().advanceAttemptNr ();
12331248 transactionFront->getStopSync ().setAttemptTime (model.getClock ().now ());
12341249 transactionFront->commit ();
@@ -1264,6 +1279,19 @@ std::unique_ptr<Request> Connector::fetchFrontRequest() {
12641279 }
12651280 });
12661281
1282+ #if MO_TX_ATTEMPT_TIMEOUT == 0
1283+ // a timeout should not increase the attemptNr. Roll back to previous attemptNr
1284+ stopTx->setOnTimeoutListener ([transactionFront_capture, attemptNr_capture] () {
1285+ MO_DBG_DEBUG (" StopTx timeout -> roll back attemptNr and try again" );
1286+ if (transactionFront_capture) {
1287+ transactionFront_capture->getStopSync ().setAttemptNr (attemptNr_capture);
1288+ transactionFront_capture->commit ();
1289+ }
1290+ });
1291+ #else
1292+ (void )attemptNr_capture;
1293+ #endif
1294+
12671295 return stopTx;
12681296 }
12691297 }
0 commit comments