@@ -189,12 +189,14 @@ public function trySend(): void
189189 /**
190190 * Signal that the message was sent.
191191 */
192- public function sent (): void
192+ public function sent (bool $ pending = true ): void
193193 {
194- if ($ this ->unencrypted ) {
195- $ this ->connection ->unencrypted_new_outgoing [$ this ->getMsgId ()] = $ this ;
196- } else {
197- $ this ->connection ->new_outgoing [$ this ->getMsgId ()] = $ this ;
194+ if ($ pending ) {
195+ if ($ this ->unencrypted ) {
196+ $ this ->connection ->unencrypted_new_outgoing [$ this ->getMsgId ()] = $ this ;
197+ } else {
198+ $ this ->connection ->new_outgoing [$ this ->getMsgId ()] = $ this ;
199+ }
198200 }
199201 if ($ this ->sent === null && $ this ->isMethod ) {
200202 $ this ->connection ->inFlightGauge ?->inc([
@@ -206,10 +208,13 @@ public function sent(): void
206208 $ this ->unlink ();
207209 }
208210 $ this ->sent = hrtime (true );
209- if ($ this ->contentRelated ) {
211+ if ($ this ->contentRelated && $ pending ) {
212+ $ self = \WeakReference::create ($ this );
210213 $ this ->checkTimer = EventLoop::delay (
211214 $ this ->connection ->API ->getSettings ()->getConnection ()->getTimeout (),
212- $ this ->check (...)
215+ static function () use ($ self ): void {
216+ $ self ->get ()?->check();
217+ }
213218 );
214219 }
215220 if (isset ($ this ->sendDeferred )) {
@@ -234,6 +239,10 @@ public function unlink(): void
234239 }
235240 $ this ->connection ->pendingOutgoingGauge ?->dec();
236241 }
242+ if ($ this ->checkTimer !== null ) {
243+ EventLoop::cancel ($ this ->checkTimer );
244+ $ this ->checkTimer = null ;
245+ }
237246 }
238247 private function check (): void
239248 {
@@ -243,9 +252,12 @@ private function check(): void
243252 $ shared = $ this ->connection ->getShared ();
244253 $ settings = $ shared ->getSettings ();
245254 $ timeout = $ settings ->getTimeout ();
255+ $ self = \WeakReference::create ($ this );
246256 $ this ->checkTimer = EventLoop::delay (
247257 $ timeout ,
248- $ this ->check (...)
258+ static function () use ($ self ): void {
259+ $ self ->get ()?->check();
260+ }
249261 );
250262
251263 \assert ($ this ->msgId !== null );
@@ -270,9 +282,7 @@ public function reply($result): void
270282 // It can happen, no big deal
271283 return ;
272284 }
273- if (!($ this ->state & self ::STATE_SENT )) {
274- $ this ->sent ();
275- }
285+ $ this ->sent (false );
276286 if ($ this ->checkTimer !== null ) {
277287 EventLoop::cancel ($ this ->checkTimer );
278288 $ this ->checkTimer = null ;
0 commit comments