danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.83k stars 654 forks source link

Madeline hangs when work with larger files. #1447

Closed KarimQaderi closed 9 months ago

KarimQaderi commented 9 months ago

When I send a 537 MB file, it stops at 85%

$this->madelineProto->messages->sendMedia([
            'peer' => $channelName,
            'message' => $message,
            'media' => [
                '_' => 'inputMediaUploadedDocument',
                'file' => $filePath,
                'attributes' => [['_' => 'documentAttributeFilename', 'file_name' => $fileName]]
            ]
        ]);
entry, bk_gate:             Amp\ByteStream\StreamException: Failed to write to stream (8): fwrite(): Send of 63 bytes failed with errno=32 Broken pipe in vendor/amphp/byte-stream/src/WritableResourceStream.php:137
Stack trace:
#0 vendor/amphp/byte-stream/src/WritableResourceStream.php(245): Amp\ByteStream\WritableResourceStream::Amp\ByteStream\{closure}()
#1 vendor/danog/ipc/lib/Sync/ChannelledSocket.php(42): Amp\ByteStream\WritableResourceStream->write()
#2 vendor/danog/madelineproto/src/Ipc/ClientAbstract.php(160): Amp\Ipc\Sync\ChannelledSocket->send()
#3 vendor/danog/madelineproto/src/Ipc/Wrapper.php(217): danog\MadelineProto\Ipc\ClientAbstract->__call()
#4 vendor/danog/madelineproto/src/MTProtoTools/Files.php(291): danog\MadelineProto\Ipc\Wrapper->danog\MadelineProto\Ipc\{closure}()
#5 vendor/danog/madelineproto/src/MTProtoTools/Files.php(320): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}()
#6 vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
#7 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#10 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#11 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#13 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#14 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#15 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#16 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#17 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#18 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#19 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#20 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#21 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#22 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#23 {main}

Next Amp\Ipc\Sync\ChannelException: Sending on the channel failed. Did the context die? in vendor/danog/ipc/lib/Sync/ChannelledSocket.php:44
Stack trace:
#0 vendor/danog/madelineproto/src/Ipc/ClientAbstract.php(160): Amp\Ipc\Sync\ChannelledSocket->send()
#1 vendor/danog/madelineproto/src/Ipc/Wrapper.php(217): danog\MadelineProto\Ipc\ClientAbstract->__call()
#2 vendor/danog/madelineproto/src/MTProtoTools/Files.php(291): danog\MadelineProto\Ipc\Wrapper->danog\MadelineProto\Ipc\{closure}()
#3 vendor/danog/madelineproto/src/MTProtoTools/Files.php(320): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}()
#4 vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
#5 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}()
#6 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#9 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#10 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#11 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#13 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#14 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#15 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#16 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#17 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#18 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#19 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#20 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#21 {main}
Server, bk_gate:            Got error while calling IPC method: Amp\ByteStream\StreamException: Failed to write to stream (8): fwrite(): Send of 63 bytes failed with errno=32 Broken pipe in vendor/amphp/byte-stream/src/WritableResourceStream.php:137
Stack trace:
#0 vendor/amphp/byte-stream/src/WritableResourceStream.php(245): Amp\ByteStream\WritableResourceStream::Amp\ByteStream\{closure}()
#1 vendor/danog/ipc/lib/Sync/ChannelledSocket.php(42): Amp\ByteStream\WritableResourceStream->write()
#2 vendor/danog/madelineproto/src/Ipc/ClientAbstract.php(160): Amp\Ipc\Sync\ChannelledSocket->send()
#3 vendor/danog/madelineproto/src/Ipc/Wrapper.php(217): danog\MadelineProto\Ipc\ClientAbstract->__call()
#4 vendor/danog/madelineproto/src/MTProtoTools/Files.php(291): danog\MadelineProto\Ipc\Wrapper->danog\MadelineProto\Ipc\{closure}()
#5 vendor/danog/madelineproto/src/MTProtoTools/Files.php(320): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}()
#6 vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
#7 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#10 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#11 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#13 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#14 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#15 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#16 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#17 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#18 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#19 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#20 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#21 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#22 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#23 {main}

Next Amp\Ipc\Sync\ChannelException: Sending on the channel failed. Did the context die? in vendor/danog/ipc/lib/Sync/ChannelledSocket.php:44
Stack trace:
#0 vendor/danog/madelineproto/src/Ipc/ClientAbstract.php(160): Amp\Ipc\Sync\ChannelledSocket->send()
#1 vendor/danog/madelineproto/src/Ipc/Wrapper.php(217): danog\MadelineProto\Ipc\ClientAbstract->__call()
#2 vendor/danog/madelineproto/src/MTProtoTools/Files.php(291): danog\MadelineProto\Ipc\Wrapper->danog\MadelineProto\Ipc\{closure}()
#3 vendor/danog/madelineproto/src/MTProtoTools/Files.php(320): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}()
#4 vendor/amphp/amp/src/functions.php(34): danog\MadelineProto\MTProto->danog\MadelineProto\MTProtoTools\{closure}()
#5 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Amp\{closure}()
#6 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(562): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#9 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#10 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#11 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#13 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#14 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#15 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#16 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#17 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#18 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#19 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#20 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#21 {main}
Server, bk_gate:            Got error while trying to send result of uploadFromCallable: Amp\Ipc\Sync\ChannelException: The channel was already closed! in vendor/danog/ipc/lib/Sync/ChannelledSocket.php:39
Stack trace:
#0 vendor/danog/madelineproto/src/Ipc/Server.php(259): Amp\Ipc\Sync\ChannelledSocket->send()
#1 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): danog\MadelineProto\Ipc\Server->clientRequest()
#2 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#3 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#4 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(171): Fiber->throw()
#5 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#6 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#9 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#10 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#11 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#13 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#14 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#15 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#16 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#17 {main}
Server, bk_gate:            Got error while trying to send error of error of uploadFromCallable: Amp\Ipc\Sync\ChannelException: The channel was already closed! in vendor/danog/ipc/lib/Sync/ChannelledSocket.php:39
Stack trace:
#0 vendor/danog/madelineproto/src/Ipc/Server.php(263): Amp\Ipc\Sync\ChannelledSocket->send()
#1 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): danog\MadelineProto\Ipc\Server->clientRequest()
#2 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#3 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#4 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(171): Fiber->throw()
#5 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#6 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#7 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(497): Fiber->resume()
#9 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#10 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#11 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#13 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#14 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#15 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#16 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
#17 {main}
entry, bk_gate:             Amp\Ipc\Sync\ChannelException: The channel was already closed! in vendor/danog/ipc/lib/Sync/ChannelledSocket.php:39
Stack trace:
#0 vendor/danog/madelineproto/src/Ipc/ClientAbstract.php(160): Amp\Ipc\Sync\ChannelledSocket->send()
#1 vendor/danog/madelineproto/src/Ipc/Wrapper.php(217): danog\MadelineProto\Ipc\ClientAbstract->__call()
#2 vendor/danog/madelineproto/src/MTProtoTools/Files.php(239): danog\MadelineProto\Ipc\Wrapper->danog\MadelineProto\Ipc\{closure}()
#3 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): danog\MadelineProto\MTProto::danog\MadelineProto\MTProtoTools\{closure}()
#4 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#5 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#6 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#7 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#8 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#9 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#10 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(64): Fiber->resume()
#11 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(425): Revolt\EventLoop\Internal\DriverSuspension::Revolt\EventLoop\Internal\{closure}()
#12 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(616): Revolt\EventLoop\Internal\AbstractDriver->invokeMicrotasks()
#13 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#14 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(498): Fiber->start()
#15 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(553): Revolt\EventLoop\Internal\AbstractDriver->invokeCallbacks()
#16 [internal function]: Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#17 vendor/revolt/event-loop/src/EventLoop/Internal/AbstractDriver.php(94): Fiber->resume()
#18 vendor/revolt/event-loop/src/EventLoop/Internal/DriverSuspension.php(117): Revolt\EventLoop\Internal\AbstractDriver->Revolt\EventLoop\Internal\{closure}()
#19 vendor/amphp/amp/src/Future.php(251): Revolt\EventLoop\Internal\DriverSuspension->suspend()
#20 vendor/danog/madelineproto/src/Ipc/Server.php(165): Amp\Future->await()
#21 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(119): danog\MadelineProto\Ipc\Server::waitShutdown()
#22 vendor/danog/madelineproto/src/Ipc/Runner/entry.php(154): danog\MadelineProto\Ipc\Runner\{closure}()
danog commented 9 months ago

Are you uploading files via web? This error usually indicates that the client script (the one serving the request via new API...) has disconnected from the IPC server.

Please attach the full logfile, it might contain more information, still I would recommend digging in the direction of timeouts (execution time, etc) in the webserver.

danog commented 9 months ago

Especially when using litespeed, there's a common issue related to file sizes, see https://support.cpanel.net/hc/en-us/articles/4654688978839-Not-Able-To-Download-Big-Files-From-cPanel-When-Accessed-Via-Service-Subdomain

KarimQaderi commented 9 months ago

log.txt

I use Job (crontab) aapanel

danog commented 9 months ago

This is 100% a timeout in the cronjob, please use a screen session to run the script.

The logs contain some seq holes: this was a bug unrelated to files introduced by a v7->v8 breaking change in the danog/loop actor library, which might have held back some updates (a restart should fix that issue); a fix for that bug will be present in beta171.

danog commented 9 months ago

Released.

KarimQaderi commented 9 months ago

tnx