Skip to content

Commit 2b7e9e8

Browse files
committed
Fix some other issues
1 parent e01a725 commit 2b7e9e8

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

src/API.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final class API extends AbstractAPI
5151
*
5252
* @var string
5353
*/
54-
public const RELEASE = '8.4.15';
54+
public const RELEASE = '8.4.16';
5555
/**
5656
* We're not logged in.
5757
*

src/MTProto/MTProtoOutgoingMessage.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/MTProtoSession/CallHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function methodRecall(MTProtoOutgoingMessage $request, ?int $forceDatacen
7777
$request->cancellation?->subscribe(static fn () => EventLoop::cancel($id));
7878
$defer = $d->getFuture();
7979
}
80+
$request->unlink();
8081
if ($defer) {
8182
$defer->finally(
8283
fn () => $this->methodRecall($request, $forceDatacenter)
@@ -88,7 +89,6 @@ public function methodRecall(MTProtoOutgoingMessage $request, ?int $forceDatacen
8889
/** @var MTProtoOutgoingMessage */
8990
$request->setMsgId(null);
9091
$request->setSeqNo(null);
91-
$request->unlink();
9292
}
9393
if ($datacenter === $this->datacenter) {
9494
EventLoop::queue($this->sendMessage(...), $request);

0 commit comments

Comments
 (0)