Skip to content

nextLine() hangs (infinite loop) #291

Open
@sergiy-petrov

Description

@sergiy-petrov

Describe the bug
When i try to search all folders using $client->getFolders() method the script just gets into infinite loop. I tried to debug it by myself and find out that when reading next char of the stream always returning an empty string.

This happens right after i received ' BYE Connection closed.' After closing connection i expect to receive 'logout' or something like that, but instead the script just hangs infinitely.

Used config

$cm = new ClientManager(['options' => [
            'debug' => true,
        ]]);

        $client = $cm->make([
            'host'           => 'outlook.office365.com',
            'port'           => 993,
            'encryption'     => 'ssl',
            'validate_cert'  => true,
            'protocol'       => 'imap',
            'username'       => $username,
            'password'       => $token,
            'authentication' => 'oauth',
        ]);

Code to Reproduce
The troubling code section which produces the reported bug.

\Webklex\PHPIMAP\Connection\Protocols\ImapProtocol::nextLine()

    public function nextLine(): string {
        $line = "";
        while (($next_char = fread($this->stream, 1)) !== false && $next_char !== "\n") {
           dump($next_char); // i added this by myself to debug - always return empty string (screenshot below)
            $line .= $next_char; // always return empty string ''
        }
        if ($line === "") {
            throw new RuntimeException('empty response');
        }
        if ($this->debug) echo "<< ".$line."\n";
        return $line . "\n";
    }

Expected behavior

Hard to say what is expected result, but i assume this should be handled somehow.

Screenshots
image

Desktop / Server (please complete the following information):

  • OS: [Ubuntu]
  • PHP: [8.0.23] (cli)
  • Version [v4.0.2]
  • Provider [Outlook]

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