diff --git a/src/internal.c b/src/internal.c index f78299161..286c26c6f 100644 --- a/src/internal.c +++ b/src/internal.c @@ -20640,8 +20640,25 @@ int SendAlert(WOLFSSL* ssl, int severity, int type) /* check for available size */ outputSz = ALERT_SIZE + MAX_MSG_EXTRA + dtlsExtra; - if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) + if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) { +#ifdef WOLFSSL_DTLS + /* If CheckAvailableSize returned WANT_WRITE due to a blocking write + * then discard pending output and just send the alert. */ + if (ssl->options.dtls) { + if (ret != WANT_WRITE || severity != alert_fatal) + return ret; + ShrinkOutputBuffer(ssl); + if ((ret = CheckAvailableSize(ssl, outputSz)) != 0) { + return ret; + } + } + else { + return ret; + } +#else return ret; +#endif + } /* Check output buffer */ if (ssl->buffers.outputBuffer.buffer == NULL)