Skip to content

Commit 7e7a775

Browse files
committed
Do not resume suspension on destruct
1 parent c102b62 commit 7e7a775

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ReadableResourceStream.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ public function isReadable(): bool
240240
public function close(): void
241241
{
242242
if (\is_resource($this->resource) && \get_resource_type($this->resource) === 'stream') {
243-
// Error suppression, as resource might already be closed
244243
$meta = \stream_get_meta_data($this->resource);
245244

246245
if (\str_contains($meta["mode"], "+")) {
@@ -251,6 +250,9 @@ public function close(): void
251250
}
252251
}
253252

253+
$this->suspension?->resume();
254+
$this->suspension = null;
255+
254256
$this->free();
255257
}
256258

@@ -328,9 +330,6 @@ private function free(): void
328330
$this->readable = false;
329331
$this->resource = null;
330332

331-
$this->suspension?->resume();
332-
$this->suspension = null;
333-
334333
EventLoop::cancel($this->callbackId);
335334

336335
if (!$this->onClose->isComplete()) {

test/ResourceStreamTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ public function testThrowsOnPendingRead(): void
170170
async(fn () => $b->read())->await();
171171
}
172172

173+
public function testCloseWithPendingRead(): void
174+
{
175+
/** @noinspection PhpUnusedLocalVariableInspection Required to keep reference */
176+
[$a, $b] = $this->getStreamPair();
177+
178+
$future = async($b->read(...));
179+
async($b->close(...));
180+
181+
self::assertFalse($b->isClosed());
182+
183+
self::assertNull($future->await());
184+
185+
self::assertTrue($b->isClosed());
186+
}
187+
173188
public function testResolveSuccessOnClosedStream(): void
174189
{
175190
[, $b] = $this->getStreamPair();

0 commit comments

Comments
 (0)