@@ -231,21 +231,37 @@ func getTPCCState(ctx context.Context) *tpccState {
231
231
}
232
232
233
233
// Run implements Workloader interface
234
- func (w * Workloader ) Run (ctx context.Context , threadID int ) error {
234
+ func (w * Workloader ) Run (ctx context.Context , threadID int ) (err error ) {
235
+ defer func () {
236
+ if r := recover (); r != nil {
237
+ err = fmt .Errorf ("panic in TPC-C Run (thread %d): %v" , threadID , r )
238
+ }
239
+ }()
240
+
235
241
s := getTPCCState (ctx )
236
242
refreshConn := false
237
243
244
+ // Helper function to safely refresh connection with panic recovery
245
+ safeRefreshConn := func () error {
246
+ defer func () {
247
+ if r := recover (); r != nil {
248
+ err = fmt .Errorf ("panic during connection refresh (thread %d): %v" , threadID , r )
249
+ }
250
+ }()
251
+ return s .RefreshConn (ctx )
252
+ }
253
+
238
254
// Check if automatic connection refresh is needed
239
255
if w .cfg .ConnRefreshInterval > 0 && time .Since (s .lastConnRefresh ) >= w .cfg .ConnRefreshInterval {
240
- if err := s . RefreshConn ( ctx ); err != nil {
241
- return err
256
+ if err := safeRefreshConn ( ); err != nil {
257
+ return fmt . Errorf ( "automatic connection refresh failed (thread %d): %w" , threadID , err )
242
258
}
243
259
s .lastConnRefresh = time .Now ()
244
260
refreshConn = true
245
261
} else if err := s .Conn .PingContext (ctx ); err != nil {
246
262
// Fallback to ping-based refresh if automatic refresh didn't happen
247
- if err := s . RefreshConn ( ctx ); err != nil {
248
- return err
263
+ if err := safeRefreshConn ( ); err != nil {
264
+ return fmt . Errorf ( "ping-based connection refresh failed (thread %d): %w" , threadID , err )
249
265
}
250
266
s .lastConnRefresh = time .Now ()
251
267
refreshConn = true
@@ -325,7 +341,7 @@ func (w *Workloader) Run(ctx context.Context, threadID int) error {
325
341
}
326
342
327
343
start := time .Now ()
328
- err : = txn .action (ctx , threadID )
344
+ err = txn .action (ctx , threadID )
329
345
330
346
w .rtMeasurement .Measure (txn .name , time .Now ().Sub (start ), err )
331
347
0 commit comments