@@ -116,7 +116,7 @@ void _noteSuspendTransactionDebug(void)
116116 */
117117NOTE_C_STATIC uint32_t _noteTransaction_calculateTimeoutMs (J * req , bool isReq )
118118{
119- uint32_t result = (CARD_INTER_TRANSACTION_TIMEOUT_SEC * 1000 );
119+ uint32_t result = (( CARD_INTER_TRANSACTION_TIMEOUT_SEC - 1 ) * 1000 );
120120
121121 // Interrogate the request
122122 if (JContainsString (req , (isReq ? "req" : "cmd" ), "note.add" )) {
@@ -137,13 +137,13 @@ NOTE_C_STATIC uint32_t _noteTransaction_calculateTimeoutMs(J *req, bool isReq)
137137 } else if (JIsPresent (req , "seconds" )) {
138138 NOTE_C_LOG_DEBUG ("Using `seconds` parameter value for timeout." );
139139 result = (JGetInt (req , "seconds" ) * 1000 );
140- } else {
141- NOTE_C_LOG_DEBUG ("No `milliseconds` or `seconds` parameter "
142- "provided. Defaulting to 90-second timeout." );
143- result = (90 * 1000 );
144140 }
145141 }
146142
143+ // Add one second to the timeout, to provide time for the Notecard to
144+ // timeout first, then report the timeout to the host, when applicable.
145+ result += 1000 ;
146+
147147 return result ;
148148}
149149
@@ -436,9 +436,6 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard)
436436 // Serialize the JSON request
437437 char * json = JPrintUnformatted (req ); // `json` allocated, must be freed
438438 if (json == NULL ) {
439- if (lockNotecard ) {
440- _UnlockNote ();
441- }
442439 _TransactionStop ();
443440 NOTE_C_LOG_ERROR (ERRSTR ("failed to serialize JSON request" , c_mem ));
444441 return NULL ;
@@ -492,28 +489,6 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard)
492489 }
493490#endif
494491
495- // If a reset of the I/O interface is required for any reason, do it now.
496- // We must do this before acquiring lock.
497- if (resetRequired ) {
498- NOTE_C_LOG_DEBUG ("Resetting Notecard I/O Interface..." );
499- if (!NoteReset ()) {
500- _Free (json );
501- _TransactionStop ();
502- const char * errStr = ERRSTR ("failed to reset Notecard interface {io}" , c_iobad );
503- if (cmdFound ) {
504- NOTE_C_LOG_ERROR (errStr );
505- return NULL ;
506- }
507- return _errDoc (id , errStr );
508- }
509- }
510-
511- // Take the lock on the Notecard. This is required to ensure that we don't
512- // have multiple threads trying to access the Notecard at the same time.
513- if (lockNotecard ) {
514- _LockNote ();
515- }
516-
517492 // Calculate the transaction timeout based on the parameters in the request.
518493 const uint32_t transactionTimeoutMs = _noteTransaction_calculateTimeoutMs (req , reqFound );
519494
@@ -547,6 +522,30 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard)
547522 }
548523#endif // !NOTE_C_LOW_MEM
549524
525+ // Take the lock on the Notecard. This is required to ensure that we don't
526+ // have multiple threads trying to access the Notecard at the same time.
527+ if (lockNotecard ) {
528+ _LockNote ();
529+ }
530+
531+ // If a reset of the I/O interface is required for any reason, do it now.
532+ if (resetRequired ) {
533+ NOTE_C_LOG_DEBUG ("Resetting Notecard I/O Interface..." );
534+ if ((resetRequired = !_Reset ())) {
535+ if (lockNotecard ) {
536+ _UnlockNote ();
537+ }
538+ _Free (json );
539+ _TransactionStop ();
540+ const char * errStr = ERRSTR ("failed to reset Notecard interface {io}" , c_iobad );
541+ if (cmdFound ) {
542+ NOTE_C_LOG_ERROR (errStr );
543+ return NULL ;
544+ }
545+ return _errDoc (id , errStr );
546+ }
547+ }
548+
550549 // If we're performing retries, this is where we come back to
551550 // after a failed transaction.
552551 const char * errStr = NULL ;
0 commit comments