mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-19 11:04:42 +00:00
configd: improve error handling while configd is either not active or not functional.
- reconnecting the socket stream_socket_client() is safe while not executing commands - if configd dies during communication, we should log and retun an empty response. The caller should handle operation, since you can't be sure restarting the action is a safe operation. closes https://github.com/opnsense/core/pull/3744
This commit is contained in:
parent
65212fcded
commit
817be51986
@ -80,21 +80,24 @@ class Backend
|
||||
|
||||
// wait until socket exist for a maximum of $connect_timeout
|
||||
$timeout_wait = $connect_timeout;
|
||||
while (!file_exists($this->configdSocket)) {
|
||||
while (
|
||||
!file_exists($this->configdSocket) ||
|
||||
($stream = @stream_socket_client('unix://'.$this->configdSocket, $errorNumber, $errorMessage, $poll_timeout)) === false
|
||||
) {
|
||||
sleep(1);
|
||||
$timeout_wait -= 1;
|
||||
if ($timeout_wait <= 0) {
|
||||
$this->getLogger()->error("failed waiting for configd (doesn't seem to be running)");
|
||||
if (file_exists($this->configdSocket)) {
|
||||
$this->getLogger()->error("Failed to connect to configd socket: $errorMessage while executing " . $event);
|
||||
return null;
|
||||
} else {
|
||||
$this->getLogger()->error("failed waiting for configd (doesn't seem to be running)");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$resp = '';
|
||||
$stream = @stream_socket_client('unix://'.$this->configdSocket, $errorNumber, $errorMessage, $poll_timeout);
|
||||
if ($stream === false) {
|
||||
$this->getLogger()->error("Failed to connect to configd socket: $errorMessage while executing " . $event);
|
||||
return null;
|
||||
}
|
||||
|
||||
stream_set_timeout($stream, $poll_timeout);
|
||||
// send command
|
||||
@ -118,6 +121,9 @@ class Backend
|
||||
if ((time() - $starttime) > $timeout) {
|
||||
$this->getLogger()->error("Timeout (".$timeout.") executing : ".$event);
|
||||
return null;
|
||||
} elseif (feof($stream)) {
|
||||
$this->getLogger()->error("Configd disconnected while executing : ".$event);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user