Skip to content

Bug: Typed property MTProto::$logger accessed before initialization during session deserialization #1710

@Mationetap

Description

@Mationetap

Description

During unserialize() of a session file, DataCenter->__wakeup() is triggered which calls DataCenterConnection->reconnect()Connection->setExtra(). At line 584 of Connection.php:

$this->API->logger = $this->API->logger;

This self-assignment accesses the typed property MTProto::$logger before the parent MTProto object has finished deserializing, resulting in:

Error: Typed property danog\MadelineProto\MTProto::$logger must not be accessed before initialization

Stack trace

Connection.php:584            setExtra()
DataCenterConnection.php:349  connectMore()
DataCenterConnection.php:326  connect()
DataCenterConnection.php:403  reconnect()
DataCenter.php:115            __wakeup()
SessionPaths.php:218          unserialize()
Serialization.php:219         unserialize()
API.php:344                   wakeup()
API.php:194                   connectToMadelineProto()

How to reproduce

  • Long-lived session file (~11MB, ~4600 peers in PeerDatabase)
  • Session idle for several hours (DC connections become stale)
  • On next new API(sessionPath, settings), deserialization triggers __wakeup on DataCenter, which tries to reconnect stale DCs before MTProto is fully initialized
  • The error is persistent — once it happens, the session cannot be deserialized at all without patching

MadelineProto log

Serialization:          MadelineProto is starting, please wait...
ProcessRunner:          Got message from worker: Error: Typed property danog\MadelineProto\MTProto::$logger
                        must not be accessed before initialization
                        in /vendor/danog/madelineproto/src/Connection.php:584
#0 DataCenterConnection.php(349): Connection->setExtra(Object(DataCenterConnection), 2, 0)
#1 DataCenterConnection.php(326): DataCenterConnection->connectMore(1)
#2 DataCenterConnection.php(403): DataCenterConnection->connect()
#3 DataCenter.php(115): DataCenterConnection->reconnect()
#4 [internal function]: DataCenter->__wakeup()
#5 SessionPaths.php(218): unserialize('O:30:"danog\Mad...')

Workaround

// Connection.php:584 — wrap in try/catch to handle uninitialized logger during __wakeup
try { $this->API->logger = $this->API->logger; } catch (\Error $e) {}

After applying this one-line patch, the session deserializes successfully, reconnects to DCs, and works normally. The account remains fully functional.

Environment

  • MadelineProto 8.6.4
  • PHP 8.2
  • Linux (Debian Bookworm, Docker)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions