Skip to content

Commit 947ee07

Browse files
committed
Fix reconnection parameters - more specific reconnect within function areas to prevent filesize 0 written after original disconnect
1 parent df9f0f2 commit 947ee07

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

inc/irrquery.inc

+21-17
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,9 @@ class IRRQuery {
104104
function _send($output)
105105
{
106106
$this->lastcommand = rtrim($output);
107-
$count = 0;
108107
// Attempt to send the command
109108
$r = @fwrite($this->fp, $output);
110109

111-
while ($r == FALSE && $count < 3) {
112-
/*
113-
if the command fails, then let's clone the file handle,
114-
wait a second, reconnect, and try again. We will try this 3 times.
115-
*/
116-
status(STATUS_ERROR, "IRR Query - Error on write. Re-connecting...");
117-
118-
// Make sure we don't leave dangling file pointers around
119-
fclose($this->fp);
120-
121-
sleep(1);
122-
$this->connect($this->host, $this->port);
123-
$count += 1;
124-
$r = @fwrite($this->fp, $output);
125-
}
126-
127110
if ($r === FALSE) {
128111
status(STATUS_ERROR, "IRR Query - Error on write. Re-connect issue...");
129112
return FALSE;
@@ -315,6 +298,17 @@ class IRRQuery {
315298
if (($results = $this->_cache_query("origin", $origin)) != FALSE)
316299
return $results;
317300

301+
/* Validate if socket connection is exists */
302+
if (feof($this->fp) === true)
303+
{
304+
status(STATUS_ERROR, "get_v4_routes_by_origin socket closed.");
305+
fclose($this->fp);
306+
sleep(2);
307+
$this->connect($this->host, $this->port);
308+
status(STATUS_ERROR, "get_v4_routes_by_origin reconnecting socket.");
309+
}
310+
311+
318312
/* Get v4 prefixes */
319313
$this->_send("!g{$origin}\n");
320314

@@ -349,6 +343,16 @@ class IRRQuery {
349343
if (($results = $this->_cache_query("origin6", $origin)) != FALSE)
350344
return $results;
351345

346+
/* Validate if socket connection is exists */
347+
if (feof($this->fp) === true)
348+
{
349+
status(STATUS_ERROR, "get_v6_routes_by_origin socket closed.");
350+
fclose($this->fp);
351+
sleep(2);
352+
$this->connect($this->host, $this->port);
353+
status(STATUS_ERROR, "get_v6_routes_by_origin reconnecting socket");
354+
}
355+
352356
/* Get v6 prefixes */
353357
$this->_send("!6{$origin}\n");
354358
if (($results = $this->_response()) == FALSE)

0 commit comments

Comments
 (0)