-
Notifications
You must be signed in to change notification settings - Fork 59
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
TransportException: connection to server 'myServer.com:10011' lost #204
Comments
2 possible quick resolutions come to mind:
|
PR #195 might also resolve this issue. |
Nice analysis! Adding a I would need to double-check this, but it makes sense in theory. But great. Then we have now two options to solve this issue:
Do you want to create a PR for your mentioned solution @MatthiasHeinz or shall I? Then we only need to decide, which one the better is. 😅 I'm still waiting for feedback from @ronindesign regarding this (and all other open PRs). 😢 If nobody reviews my PR soon, I can also simply merge them and then everyone can at least test the DEV branch. |
Appreciate the patience, #195 has been merged. Please reopen this if not resolved! |
I'll probably test this next week and give you guys a nudge, if the issue still persists by then; because I'm not allowed to reopen this issue. |
Unfortunately, #195 does not seem to resolve the issue entirely; instead the CPU spins in an endless loop. When calling do {
$str = $this->getTransport()->readLine();
$rpl[] = $str;
} while ($str->section(TeamSpeak3::SEPARATOR_CELL) != TeamSpeak3::ERROR); Now though, Beware: The current issue probably concerns more than just the previously mentioned use-case! |
@ronindesign Would you mind to reopen this issue based on my previous post? |
This change should help to exit stuck loops, when the library is not connected to the remote server anymore. - Adds a new function to check if a connection is established or not - Adds a PHPUnit test for the new function - Adds the connection status as condition to loops in order to abort, when it disconnected
This change should help to exit stuck loops, when the library is not connected to the remote server anymore. - Adds a new function to check if a connection is established or not - Adds a PHPUnit test for the new function - Adds the connection status as condition to loops in order to abort, when it disconnected
@MatthiasHeinz I've created a pull request to hopefully fix this issue: #206 Can you please let me know, if this solves the issue for you? I'll also try to reproduce and test this change on my side. |
This change should help to exit stuck loops, when the library is not connected to the remote server anymore. - Adds a new function to check if a connection is established or not - Adds a PHPUnit test for the new function - Adds the connection status as condition to loops in order to abort, when it disconnected
In order to recreate the endless-loop, I simply had to call this custom function (- obviously, you might want to adjust the public function getUserCount() {
$options = array("host" => "localhost", "port" => "10011", "timeout" => 10, "blocking" => true);
$object = new ServerQuery($options);
$node = $object->getHost();
$node->login($tsServer->getQueryUser(), $tsServer->getQueryPass());
$node->setExcludeQueryClients(true);
$node = $node->serverGetByPort($tsServer->getPort());
assert($node instanceof Server);
return $node->clientCount();
} As far as the reasoning goes, when the Hope, all of this information helps in your testing efforts. I'll be testing the fix probably next week, if it's merged by then. |
This change should help to exit stuck loops, when the library is not connected to the remote server anymore. - Fixes the existing `isConnected()` function to properly return TRUE or FALSE - Adds a PHPUnit test for the `isConnected()` function - Adds the connection status as condition to loops in order to abort, when it disconnected
When connected with `blocking=0` (non-blocking mode), the PHP script usually wants to stay connected, so the library shouldn't automatically disconnect it all the time. Instead, the user needs to manually disconnect.
This change should help to exit stuck loops, when the library is not connected to the remote server anymore. - Fixes the existing `isConnected()` function to properly return TRUE or FALSE - Adds a PHPUnit test for the `isConnected()` function - Adds the connection status as condition to loops in order to abort, when it disconnected
When connected with `blocking=0` (non-blocking mode), the PHP script usually wants to stay connected, so the library shouldn't automatically disconnect it all the time. Instead, the user needs to manually disconnect.
Issue #204: Fix high CPU utilization after disconnects / connection losses
I was able to reproduce the high CPU utilization. I was also able to fix it with the above merged pull request #206 . Please let me know, if this also solved the issue for you @MatthiasHeinz . :) |
Using I'm honestly not quite sure, what value I should ideally set Just wanted to let you know, that there's still some excessive CPU utilization. |
This depends on the use-case, so your PHP script and its purpose. By default, this option is set to However, if you build a bot for a TeamSpeak server, this is usually a long running PHP script, which should stay connected 24x7 on your TeamSpeak server for regular tasks (e. g. fetching data, moving clients, granting server groups, etc.). Repeatingly connecting and disconnecting would result in flood messages on your TeamSpeak server (spam the server chat about regular reconnects of this bot). In this case you set the option to And then your code logic needs to handle the proper disconnect. Otherwise, your client will time out when the PHP script exits.
This can be archived with both explained scenarios above. Depending on how often you want to fetch this data it maybe makes sense to build a bot for it to stay connected in order to avoid spaming the server chat about the regular reconnects of this client / PHP script.
I've tested a few things as normal PHP script and bot PHP script, but I could not reproduce the high CPU utilization anymore after I've applied the above recent changes / fixes. This can be still caused by your personal code, which I don't know in detail. But your code excerpt above seems to always establish a new connection, so I guess it also closes it all the time. Not sure, what the rest of your code does all the time. If you're having a class with functions, I would recommend you to create one main function, where you setup your connection and establish it and afterwards you call your respective functions / code, which should do the actual things. AFTER calling all necessary functions, tell your code to disconnect and exit the script. |
I'm still trying to fiddle with the previous code snippet.
// my code
public function getUserCount() {
$port = "10011";
$options = array("host" => "localhost", "port" => $port, "timeout" => 10, "blocking" => true);
$object = new ServerQuery($options);
$node = $object->getHost();
$node->login("my_bot_username", "my_bot_password");
$node->setExcludeQueryClients(true);
$node = $node->serverGetByPort($port);
assert($node instanceof Server);
//$object->getTransport()->disconnect(); // This line fixes the symptom, but not the underlying issue.
return $node->clientCount();
} To debug the underlying issue, I did add a couple of // ServerQuery.php
public function __destruct()
{
error_log("ServerQuery::__destruct 0");
// do not disconnect, when acting as bot in non-blocking mode
if (! $this->getTransport()->getConfig("blocking")) {
return;
}
error_log("ServerQuery::__destruct 1");
if ($this->getTransport() instanceof Transport && $this->transport->isConnected()) {
try {
error_log("ServerQuery::__destruct 1.1");
$this->request("quit");
error_log("ServerQuery::__destruct 1.2");
} catch (AdapterException) {
error_log("ServerQuery::__destruct 1.3");
return;
}
}
error_log("ServerQuery::__destruct 2");
}
// Transport.php
public function __destruct()
{
error_log("Transport::__destruct");
if ($this->adapter instanceof Adapter) {
$this->adapter->__destruct();
}
$this->disconnect();
} When running the script once, the apache log yields:
Note, that the second time Combined with the fact, that prior to the second call to Hopefully this information helps you to track the underlying issue. |
@Sebbo94BY Did you have any chance to take an other look at the endless loop issue? Did you manage to reproduce? |
Hi @MatthiasHeinz, I had a quick look at it in the past, but since I was on vacation and am currently busy with a few other topics, I had not the time and head to check this further yet. But I'll definitley take a deeper look at it within the next weeks. |
@Sebbo94BY I'm still interested to see a fix for the issue, if possible. Hopefully, your schedule has cleared a bit in the meantime. ;-) |
When calling
the
ServerQuery::__destruct()
and thusthis->request("quit")
is being called (c.f. https://github.com/planetteamspeak/ts3phpframework/blob/dev/src/Adapter/ServerQuery.php#L106).This line used to catch
Exception
instead ofAdapterException
(c.f.ts3phpframework/libraries/TeamSpeak3/Adapter/ServerQuery.php
Line 96 in 035d242
TransportException
thrown inreadLine(...)
(c.f. https://github.com/planetteamspeak/ts3phpframework/blob/dev/src/Transport/TCP.php#L162), when callingthis->request("quit")
.For that reason, the
TransportException
is thrown and not caught anymore.The text was updated successfully, but these errors were encountered: