Close QUIC connection if writer is still blocked while calling OnCanWrite.

Protected by FLAGS_quic_reloadable_flag_quic_close_connection_in_on_can_write_with_blocked_writer.

PiperOrigin-RevId: 329813983
Change-Id: I0f2b8f1de1a851aa7e8f543afb72152e2d66804b
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index 4069501..c0ec674 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -2306,7 +2306,21 @@
   if (!connected_) {
     return;
   }
-  DCHECK(!writer_->IsWriteBlocked());
+  if (GetQuicReloadableFlag(
+          quic_close_connection_in_on_can_write_with_blocked_writer)) {
+    QUIC_RELOADABLE_FLAG_COUNT(
+        quic_close_connection_in_on_can_write_with_blocked_writer);
+    if (writer_->IsWriteBlocked()) {
+      const std::string error_details =
+          "Writer is blocked while calling OnCanWrite.";
+      QUIC_BUG << ENDPOINT << error_details;
+      CloseConnection(QUIC_INTERNAL_ERROR, error_details,
+                      ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
+      return;
+    }
+  } else {
+    DCHECK(!writer_->IsWriteBlocked());
+  }
 
   // Add a flusher to ensure the connection is marked app-limited.
   ScopedPacketFlusher flusher(this);