Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fread() hangs when reading from client upon disconnection #71

Closed
jaesonarsoftware opened this issue Oct 18, 2021 · 4 comments
Closed

fread() hangs when reading from client upon disconnection #71

jaesonarsoftware opened this issue Oct 18, 2021 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@jaesonarsoftware
Copy link

jaesonarsoftware commented Oct 18, 2021

Version of RouterOS
6.44.5

To Reproduce

Change to your router's IP, run this script. When the sleep(10) is waiting, unlink the router from the network, or somehow break the network connection. The following read() will hang and loop this forever:
<warning>PHP Warning: fread(): SSL: Success in /usr/share/sonar/vendor/evilfreelancer/routeros-api-php/src/Streams/ResourceStream.php on line 51</warning>

The code will not continue even if the network is plugged back in. It just outputs the above line forever. The process must be killed. The issue happens whether socket_blocking is true or false.

use \RouterOS\Client;
use \RouterOS\Query;
$context = [
    'verify_peer' => false,
    'allowed_self_signed' => true,
    'verify_peer_name' => false,
];

       
$clientConfig = [
    'host' => '192.168.0.1',
    'user' => 'admin',
    'pass' => '',
    'port' => 8729,
    'ssl' => true,
    'ssl_options' => $context,
    'timeout' => 10,
    'ssh_port' => 10,
    'ssh_timeout' => 10,
    'socket_timeout' => 10,
    'socket_blocking' => false,
];
$client = new Client($clientConfig);
$addRequest = (new \RouterOS\Query("/ip/firewall/address-list/add"));
$addRequest->equal('address', "387.213.124.893");
$addRequest->equal('list', "jaedumb");
$addRequest->equal('comment', "jaedumb");
$addRequest->tag(22);
$client->query($addRequest);
$addRequest = (new \RouterOS\Query("/ip/firewall/address-list/add"));
$addRequest->equal('address', "387.213.124.893");
$addRequest->equal('list', "jaedumb");
$addRequest->equal('comment', "jaedumb");
$addRequest->tag(23);
sleep(10);
$client->query($addRequest);
$addRequest = (new \RouterOS\Query("/ip/firewall/address-list/add"));
$addRequest->equal('address', "387.213.124.893");
$addRequest->equal('list', "jaedumb");
$addRequest->equal('comment', "jaedumb");
$addRequest->tag(24);
$client->query($addRequest);
print_r($client->read());
print_r($client->read());
print_r($client->read());

Expected behavior
A clear and concise description of what you expected to happen.

@jaesonarsoftware jaesonarsoftware added the bug Something isn't working label Oct 18, 2021
@jaesonarsoftware jaesonarsoftware changed the title fread() hangs when reading from client fread() hangs when reading from client upon disconnection Oct 18, 2021
@EvilFreelancer
Copy link
Owner

Hello! Thanks for your report, I'll check it tomorrow.

@ajisetiaji101
Copy link

hello sir, can i write query to mikrotik via api without disconnect
(https://user-images.githubusercontent.com/54074581/147867258-fc25a2f9-8bd4-49b2-b701-ffcdeb4cb504.png)

@naufkia
Copy link

naufkia commented May 25, 2022

same issue, any solution?

@EvilFreelancer
Copy link
Owner

Hi! Fixed in #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants