Skip to content

Commit

Permalink
Remove lock from websocket cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ugyballoons committed Apr 4, 2024
1 parent ea3a997 commit 02e46ab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions python/lsst/ts/rubintv/handlers/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ async def data_websocket(
async with clients_lock:
clients[client_id] = websocket
websocket_to_client[websocket] = client_id
logger.info("Num clients:", num_clients=len(clients))

try:
while True:
Expand Down Expand Up @@ -89,6 +90,7 @@ async def data_websocket(
logger.info("Unattaching:", client_id=client_id)
del clients[client_id]
del websocket_to_client[websocket]
logger.info("Num clients:", num_clients=len(clients))
await remove_client_from_services(client_id)


Expand Down
11 changes: 5 additions & 6 deletions python/lsst/ts/rubintv/handlers/websocket_notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ async def _send_json(websocket: WebSocket, a_dict: dict) -> None:
await websocket.send_json(a_dict)
except (ConnectionClosed, WebSocketDisconnect):
logger.info("Websocket disconnected uncleanly:", websocket=websocket)
async with services_lock:
if websocket in websocket_to_client:
client_id = websocket_to_client[websocket]
del clients[client_id]
del websocket_to_client[websocket]
await remove_client_from_services(client_id)
if websocket in websocket_to_client:
client_id = websocket_to_client[websocket]
del clients[client_id]
del websocket_to_client[websocket]
await remove_client_from_services(client_id)
11 changes: 1 addition & 10 deletions python/lsst/ts/rubintv/run_rubintv.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import uvicorn
from lsst.ts.rubintv.main import app
from uvicorn.config import LOGGING_CONFIG


def run_rubintv() -> None:
LOGGING_CONFIG["formatters"]["default"][
"fmt"
] = "%(asctime)s [%(name)s] %(levelprefix)s %(message)s"

# ping timeout/interval added to prevent unhandled disconnects.
# there will be a better/more understandable way of dealing with them.
uvicorn.run(
app,
host="0.0.0.0",
port=8080,
log_level="info",
ws_ping_interval=60,
ws_ping_timeout=120,
log_level="debug",
)


Expand Down
6 changes: 6 additions & 0 deletions src/js/components/TableApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ function getAllColumnNamesFromMetadata (metadata) {

function getTableColumnWidths () {
const tRow = document.querySelector('tr')
if (!tRow) {
return []
}
const cellsArr = Array.from(tRow.querySelectorAll('td'))
const cellWidths = cellsArr.map((cell) => { return cell.offsetWidth })
return cellWidths
Expand All @@ -131,6 +134,9 @@ function getTableColumnWidths () {
function redrawHeaderWidths () {
const columns = getTableColumnWidths()
const headers = Array.from(document.querySelectorAll('.grid-title'))
if (columns.length !== headers.length) {
return
}
let sum = 0
headers.forEach((title, ix) => {
const width = columns[ix]+2
Expand Down
1 change: 1 addition & 0 deletions src/js/pages/camera-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { WebsocketClient } from '../modules/ws-service-client'
const perDay = window.APP_DATA.perDay || {}
const nightReportLink = window.APP_DATA.nightReportLink || ''
const date = window.APP_DATA.date || ''

if (!window.APP_DATA.isHistorical) {
const ws = new WebsocketClient()
ws.subscribe('service', 'camera', locationName, camera.name)
Expand Down

0 comments on commit 02e46ab

Please sign in to comment.