11
11
using System . Diagnostics ;
12
12
using System . Linq ;
13
13
using System . Runtime . Serialization ;
14
+ using System . Text ;
14
15
using System . Threading ;
15
16
using System . Threading . Tasks ;
16
17
using Akka . Actor ;
@@ -1462,6 +1463,41 @@ private void BecomeWritingOrSendBufferedMessages()
1462
1463
}
1463
1464
}
1464
1465
1466
+ /// <summary>
1467
+ /// Unwraps <see cref="IWrappedMessage"/> in order to help make it easier to troubleshoot
1468
+ /// which oversized message was sent.
1469
+ /// </summary>
1470
+ /// <returns>The formatted type string.</returns>
1471
+ /// <remarks>
1472
+ /// Internal for testing purposes only.
1473
+ /// </remarks>
1474
+ internal static string LogPossiblyWrappedMessageType ( object failedMsg )
1475
+ {
1476
+ if ( failedMsg is IWrappedMessage wrappedMessage )
1477
+ {
1478
+ static void LogWrapped ( StringBuilder builder , IWrappedMessage nextMsg )
1479
+ {
1480
+ builder . Append ( $ "{ nextMsg . GetType ( ) } -->") ;
1481
+ if ( nextMsg . Message is IWrappedMessage wrappedAgain )
1482
+ {
1483
+ builder . Append ( '(' ) ;
1484
+ LogWrapped ( builder , wrappedAgain ) ; // recursively iterate through all layers of wrapping
1485
+ builder . Append ( ')' ) ;
1486
+ }
1487
+ else
1488
+ {
1489
+ builder . Append ( nextMsg . Message . GetType ( ) ) ;
1490
+ }
1491
+ }
1492
+
1493
+ var builder = new StringBuilder ( ) ;
1494
+ LogWrapped ( builder , wrappedMessage ) ;
1495
+ return builder . ToString ( ) ;
1496
+ }
1497
+
1498
+ return failedMsg . GetType ( ) . ToString ( ) ;
1499
+ }
1500
+
1465
1501
private bool WriteSend ( EndpointManager . Send send )
1466
1502
{
1467
1503
try
@@ -1486,7 +1522,7 @@ private bool WriteSend(EndpointManager.Send send)
1486
1522
string . Format ( "Discarding oversized payload sent to {0}: max allowed size {1} bytes, actual size of encoded {2} was {3} bytes." ,
1487
1523
send . Recipient ,
1488
1524
Transport . MaximumPayloadBytes ,
1489
- send . Message . GetType ( ) ,
1525
+ LogPossiblyWrappedMessageType ( send . Message ) ,
1490
1526
pdu . Length ) ) ;
1491
1527
_log . Error ( reason , "Transient association error (association remains live)" ) ;
1492
1528
return true ;
@@ -1509,15 +1545,15 @@ private bool WriteSend(EndpointManager.Send send)
1509
1545
_log . Error (
1510
1546
ex ,
1511
1547
"Serialization failed for message [{0}]. Transient association error (association remains live)" ,
1512
- send . Message . GetType ( ) ) ;
1548
+ LogPossiblyWrappedMessageType ( send . Message ) ) ;
1513
1549
return true ;
1514
1550
}
1515
1551
catch ( ArgumentException ex )
1516
1552
{
1517
1553
_log . Error (
1518
1554
ex ,
1519
1555
"Serializer threw ArgumentException for message type [{0}]. Transient association error (association remains live)" ,
1520
- send . Message . GetType ( ) ) ;
1556
+ LogPossiblyWrappedMessageType ( send . Message ) ) ;
1521
1557
return true ;
1522
1558
}
1523
1559
catch ( EndpointException ex )
0 commit comments