@@ -191,17 +191,15 @@ func (c *conn) Run(ctx context.Context) {
191191 if curDB != command .Value .CurDB && command .Value .CurDB != "" {
192192 // Maybe there's a USE statement already, never mind.
193193 if resp := c .backendConn .ExecuteCmd (ctx , pnet .MakeInitDBRequest (command .Value .CurDB )); resp .Err != nil {
194- c .replayStats .ExceptionCmds .Add (1 )
195- c .exceptionCh <- NewFailException (resp .Err , command .Value )
194+ c .onExecuteFailed (command .Value , resp .Err )
196195 c .lg .Info ("failed to use database" , zap .String ("db" , command .Value .CurDB ), zap .Error (resp .Err ))
197196 continue
198197 }
199198 curDB = command .Value .CurDB
200199 }
201200 // update psID, SQL, and params for the command.
202201 if err := c .updateExecuteStmt (command .Value ); err != nil {
203- c .replayStats .ExceptionCmds .Add (1 )
204- c .exceptionCh <- NewFailException (err , command .Value )
202+ c .onExecuteFailed (command .Value , err )
205203 continue
206204 }
207205 startTime := time .Now ()
@@ -215,16 +213,20 @@ func (c *conn) Run(ctx context.Context) {
215213 curDB = ""
216214 continue
217215 }
218- c .replayStats .ExceptionCmds .Add (1 )
219- c .exceptionCh <- NewFailException (resp .Err , command .Value )
216+ c .onExecuteFailed (command .Value , resp .Err )
220217 } else {
221218 c .updatePreparedStmts (command .Value .CapturedPsID , command .Value .Payload , resp )
222219 }
223- c .execInfoCh <- ExecInfo {
220+ // Logging should not block replaying.
221+ select {
222+ case c .execInfoCh <- ExecInfo {
224223 Command : command .Value ,
225224 StartTime : startTime ,
226225 CostTime : latency ,
226+ }:
227+ default :
227228 }
229+
228230 c .replayStats .ReplayedCmds .Add (1 )
229231 }
230232 }
@@ -340,11 +342,24 @@ func (c *conn) updateExecuteStmt(command *cmd.Command) error {
340342
341343func (c * conn ) onDisconnected (err error ) {
342344 c .replayStats .ExceptionCmds .Add (1 )
343- c .exceptionCh <- NewOtherException (err , c .upstreamConnID )
345+ // Reporting should not block replaying.
346+ select {
347+ case c .exceptionCh <- NewOtherException (err , c .upstreamConnID ):
348+ default :
349+ }
344350 clear (c .psIDMapping )
345351 clear (c .preparedStmts )
346352}
347353
354+ func (c * conn ) onExecuteFailed (command * cmd.Command , err error ) {
355+ c .replayStats .ExceptionCmds .Add (1 )
356+ // Reporting should not block replaying.
357+ select {
358+ case c .exceptionCh <- NewFailException (err , command ):
359+ default :
360+ }
361+ }
362+
348363// ExecuteCmd executes a command asynchronously by adding it to the list.
349364// Adding commands should never block because it may cause cycle wait, so we don't use channels.
350365// Conn A: wait for the lock held by conn B, and then its list becomes full and blocks the replay
0 commit comments