mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 06:17:41 +00:00
Potential fix for an issue where the telnet client was reconnecting right at the same time we try to shut down spothole, causing the stop() method to close one telnet object but then a new one is created and read from anyway.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Event, Thread
|
from threading import Event, Lock, Thread
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
import telnetlib3
|
import telnetlib3
|
||||||
@@ -40,6 +40,7 @@ class DXCluster(SpotProvider):
|
|||||||
self._LINE_PATTERN_ALLOW_RBN if self._allow_rbn_spots else self._LINE_PATTERN_EXCLUDE_RBN
|
self._LINE_PATTERN_ALLOW_RBN if self._allow_rbn_spots else self._LINE_PATTERN_EXCLUDE_RBN
|
||||||
)
|
)
|
||||||
self._telnet = None
|
self._telnet = None
|
||||||
|
self._telnet_lock = Lock()
|
||||||
self._thread = None
|
self._thread = None
|
||||||
self._stop_event = Event()
|
self._stop_event = Event()
|
||||||
|
|
||||||
@@ -49,8 +50,9 @@ class DXCluster(SpotProvider):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._stop_event.set()
|
self._stop_event.set()
|
||||||
if self._telnet:
|
with self._telnet_lock:
|
||||||
self._telnet.close()
|
if self._telnet:
|
||||||
|
self._telnet.close()
|
||||||
if self._thread:
|
if self._thread:
|
||||||
self._thread.join(timeout=15)
|
self._thread.join(timeout=15)
|
||||||
if self._thread.is_alive():
|
if self._thread.is_alive():
|
||||||
@@ -63,7 +65,14 @@ class DXCluster(SpotProvider):
|
|||||||
try:
|
try:
|
||||||
self.status = "Connecting"
|
self.status = "Connecting"
|
||||||
logger.info(f"DX Cluster {self._hostname} connecting...")
|
logger.info(f"DX Cluster {self._hostname} connecting...")
|
||||||
self._telnet = telnetlib3.Telnet(self._hostname, self._port)
|
new_telnet = telnetlib3.Telnet(self._hostname, self._port)
|
||||||
|
with self._telnet_lock:
|
||||||
|
self._telnet = new_telnet
|
||||||
|
if self._stop_event.is_set():
|
||||||
|
# stop() was called while we were connecting, close the connection rather than trying to
|
||||||
|
# read when we know it won't work
|
||||||
|
new_telnet.close()
|
||||||
|
break
|
||||||
self._telnet.read_until(self._login_prompt.encode("latin-1"))
|
self._telnet.read_until(self._login_prompt.encode("latin-1"))
|
||||||
self._telnet.write(f"{self._login_callsign}\n".encode("latin-1"))
|
self._telnet.write(f"{self._login_callsign}\n".encode("latin-1"))
|
||||||
connected = True
|
connected = True
|
||||||
|
|||||||
+13
-4
@@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from threading import Event, Thread
|
from threading import Event, Lock, Thread
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
import telnetlib3
|
import telnetlib3
|
||||||
@@ -29,6 +29,7 @@ class RBN(SpotProvider):
|
|||||||
super().__init__(name, provider_config)
|
super().__init__(name, provider_config)
|
||||||
self._port = provider_config["port"]
|
self._port = provider_config["port"]
|
||||||
self._telnet = None
|
self._telnet = None
|
||||||
|
self._telnet_lock = Lock()
|
||||||
self._thread = None
|
self._thread = None
|
||||||
self._stop_event = Event()
|
self._stop_event = Event()
|
||||||
|
|
||||||
@@ -38,8 +39,9 @@ class RBN(SpotProvider):
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self._stop_event.set()
|
self._stop_event.set()
|
||||||
if self._telnet:
|
with self._telnet_lock:
|
||||||
self._telnet.close()
|
if self._telnet:
|
||||||
|
self._telnet.close()
|
||||||
if self._thread:
|
if self._thread:
|
||||||
self._thread.join(timeout=15)
|
self._thread.join(timeout=15)
|
||||||
if self._thread.is_alive():
|
if self._thread.is_alive():
|
||||||
@@ -52,7 +54,14 @@ class RBN(SpotProvider):
|
|||||||
try:
|
try:
|
||||||
self.status = "Connecting"
|
self.status = "Connecting"
|
||||||
logger.info(f"RBN port {self._port!s} connecting...")
|
logger.info(f"RBN port {self._port!s} connecting...")
|
||||||
self._telnet = telnetlib3.Telnet("telnet.reversebeacon.net", self._port)
|
new_telnet = telnetlib3.Telnet("telnet.reversebeacon.net", self._port)
|
||||||
|
with self._telnet_lock:
|
||||||
|
self._telnet = new_telnet
|
||||||
|
if self._stop_event.is_set():
|
||||||
|
# stop() was called while we were connecting, close the connection rather than trying to
|
||||||
|
# read when we know it won't work
|
||||||
|
new_telnet.close()
|
||||||
|
break
|
||||||
self._telnet.read_until("Please enter your call: ".encode("latin-1"))
|
self._telnet.read_until("Please enter your call: ".encode("latin-1"))
|
||||||
self._telnet.write(f"{SERVER_OWNER_CALLSIGN}\n".encode("latin-1"))
|
self._telnet.write(f"{SERVER_OWNER_CALLSIGN}\n".encode("latin-1"))
|
||||||
connected = True
|
connected = True
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/add-spot.js?v=1789763826"></script>
|
<script src="/static/js/add-spot.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-add-spot").addClass("active");
|
$("#nav-link-add-spot").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
@@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/alerts.js?v=1789763826"></script>
|
<script src="/static/js/alerts.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-alerts").addClass("active");
|
$("#nav-link-alerts").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
@@ -76,8 +76,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/spotsbandsandmap.js?v=1789763826"></script>
|
<script src="/static/js/spotsbandsandmap.js?v=1789800912"></script>
|
||||||
<script src="/static/js/bands.js?v=1789763826"></script>
|
<script src="/static/js/bands.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-bands").addClass("active");
|
$("#nav-link-bands").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
+5
-5
@@ -1,6 +1,6 @@
|
|||||||
{% extends "skeleton.html" %}
|
{% extends "skeleton.html" %}
|
||||||
{% block head_extra %}
|
{% block head_extra %}
|
||||||
<link rel="stylesheet" href="/static/css/style.css?v=1789763825" type="text/css">
|
<link rel="stylesheet" href="/static/css/style.css?v=1789800912" type="text/css">
|
||||||
<link href="/static/vendor/css/bootstrap-5.3.8.min.css" rel="stylesheet">
|
<link href="/static/vendor/css/bootstrap-5.3.8.min.css" rel="stylesheet">
|
||||||
<link href="/static/vendor/css/fontawesome-6.7.2.min.css" rel="stylesheet">
|
<link href="/static/vendor/css/fontawesome-6.7.2.min.css" rel="stylesheet">
|
||||||
<link href="/static/vendor/css/solid-6.7.2.min.css" rel="stylesheet">
|
<link href="/static/vendor/css/solid-6.7.2.min.css" rel="stylesheet">
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
window.fetchEventSource = fetchEventSource;
|
window.fetchEventSource = fetchEventSource;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="/static/js/utils.js?v=1789763825"></script>
|
<script src="/static/js/utils.js?v=1789800912"></script>
|
||||||
<script src="/static/js/ui-ham.js?v=1789763825"></script>
|
<script src="/static/js/ui-ham.js?v=1789800912"></script>
|
||||||
<script src="/static/js/geo.js?v=1789763825"></script>
|
<script src="/static/js/geo.js?v=1789800912"></script>
|
||||||
<script src="/static/js/common.js?v=1789763825"></script>
|
<script src="/static/js/common.js?v=1789800912"></script>
|
||||||
{% end %}
|
{% end %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|||||||
@@ -284,7 +284,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/vendor/js/chart-4.4.9.umd.min.js"></script>
|
<script src="/static/vendor/js/chart-4.4.9.umd.min.js"></script>
|
||||||
<script src="/static/js/conditions.js?v=1789763825"></script>
|
<script src="/static/js/conditions.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-conditions").addClass("active");
|
$("#nav-link-conditions").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
+2
-2
@@ -113,8 +113,8 @@
|
|||||||
const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}";
|
const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="/static/js/spotsbandsandmap.js?v=1789763825"></script>
|
<script src="/static/js/spotsbandsandmap.js?v=1789800912"></script>
|
||||||
<script src="/static/js/map.js?v=1789763825"></script>
|
<script src="/static/js/map.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-map").addClass("active");
|
$("#nav-link-map").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
@@ -125,8 +125,8 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/spotsbandsandmap.js?v=1789763825"></script>
|
<script src="/static/js/spotsbandsandmap.js?v=1789800912"></script>
|
||||||
<script src="/static/js/spots.js?v=1789763825"></script>
|
<script src="/static/js/spots.js?v=1789800912"></script>
|
||||||
<script>$(document).ready(function () {
|
<script>$(document).ready(function () {
|
||||||
$("#nav-link-spots").addClass("active");
|
$("#nav-link-spots").addClass("active");
|
||||||
}); <!-- highlight active page in nav --></script>
|
}); <!-- highlight active page in nav --></script>
|
||||||
|
|||||||
@@ -96,7 +96,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="/static/js/status.js?v=1789763826"></script>
|
<script src="/static/js/status.js?v=1789800912"></script>
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$("#nav-link-status").addClass("active");
|
$("#nav-link-status").addClass("active");
|
||||||
|
|||||||
Reference in New Issue
Block a user