@@ -10,7 +10,13 @@ import {
1010 LoggingLevel ,
1111 createLogProxy ,
1212} from '../logging/log' ;
13- import { EventDispatcher , EventHandler , EventMap , EventTypes } from './events' ;
13+ import {
14+ EventDispatcher ,
15+ EventHandler ,
16+ EventMap ,
17+ EventTypes ,
18+ ProtocolError ,
19+ } from './events' ;
1420import {
1521 ProvidedTransportOptions ,
1622 TransportOptions ,
@@ -21,6 +27,7 @@ import {
2127 SessionConnecting ,
2228 SessionHandshaking ,
2329 SessionNoConnection ,
30+ SessionNoConnectionListeners ,
2431 SessionState ,
2532} from './sessionStateMachine' ;
2633import { Connection } from './connection' ;
@@ -277,6 +284,18 @@ export abstract class Transport<ConnType extends Connection> {
277284 onSessionGracePeriodElapsed : ( ) => {
278285 this . onSessionGracePeriodElapsed ( noConnectionSession ) ;
279286 } ,
287+ onMessageSendFailure : ( msg , reason ) => {
288+ this . log ?. error ( `failed to send message: ${ reason } ` , {
289+ ...noConnectionSession . loggingMetadata ,
290+ transportMessage : msg ,
291+ } ) ;
292+
293+ this . protocolError ( {
294+ type : ProtocolError . MessageSendFailure ,
295+ message : reason ,
296+ } ) ;
297+ this . deleteSession ( noConnectionSession , { unhealthy : true } ) ;
298+ } ,
280299 } ) ;
281300
282301 this . updateSession ( noConnectionSession ) ;
@@ -289,20 +308,36 @@ export abstract class Transport<ConnType extends Connection> {
289308 ) : SessionNoConnection {
290309 // transition to no connection
291310 let noConnectionSession : SessionNoConnection ;
311+ const listeners : SessionNoConnectionListeners = {
312+ onSessionGracePeriodElapsed : ( ) => {
313+ this . onSessionGracePeriodElapsed ( noConnectionSession ) ;
314+ } ,
315+ onMessageSendFailure : ( msg , reason ) => {
316+ this . log ?. error ( `failed to send message: ${ reason } ` , {
317+ ...noConnectionSession . loggingMetadata ,
318+ transportMessage : msg ,
319+ } ) ;
320+
321+ this . protocolError ( {
322+ type : ProtocolError . MessageSendFailure ,
323+ message : reason ,
324+ } ) ;
325+ this . deleteSession ( noConnectionSession , { unhealthy : true } ) ;
326+ } ,
327+ } ;
328+
292329 if ( session . state === SessionState . Handshaking ) {
293330 noConnectionSession =
294- SessionStateGraph . transition . HandshakingToNoConnection ( session , {
295- onSessionGracePeriodElapsed : ( ) => {
296- this . onSessionGracePeriodElapsed ( noConnectionSession ) ;
297- } ,
298- } ) ;
331+ SessionStateGraph . transition . HandshakingToNoConnection (
332+ session ,
333+ listeners ,
334+ ) ;
299335 } else {
300336 noConnectionSession =
301- SessionStateGraph . transition . ConnectedToNoConnection ( session , {
302- onSessionGracePeriodElapsed : ( ) => {
303- this . onSessionGracePeriodElapsed ( noConnectionSession ) ;
304- } ,
305- } ) ;
337+ SessionStateGraph . transition . ConnectedToNoConnection (
338+ session ,
339+ listeners ,
340+ ) ;
306341 }
307342
308343 this . updateSession ( noConnectionSession ) ;
0 commit comments