Skip to content

Commit be27ed4

Browse files
committed
fix(ctl): properly encode/decode MSG_TYPE_STATUS for dirty worker query
- Add encode_status method to BinaryProtocol - Use arbiter.dirty_arbiter.socket_path instead of env var when available
1 parent 3e6d6b9 commit be27ed4

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

gunicorn/ctl/handlers.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,13 @@ def _query_dirty_workers(self) -> list:
474474
List of dirty worker info dicts, or empty list on error
475475
"""
476476
import socket
477-
dirty_socket_path = os.environ.get('GUNICORN_DIRTY_SOCKET')
477+
478+
# Get socket path from arbiter object or environment
479+
dirty_socket_path = None
480+
if hasattr(self.arbiter, 'dirty_arbiter') and self.arbiter.dirty_arbiter:
481+
dirty_socket_path = getattr(self.arbiter.dirty_arbiter, 'socket_path', None)
482+
if not dirty_socket_path:
483+
dirty_socket_path = os.environ.get('GUNICORN_DIRTY_SOCKET')
478484
if not dirty_socket_path:
479485
return []
480486

@@ -500,8 +506,10 @@ def _query_dirty_workers(self) -> list:
500506
data = response.get("data", {})
501507
return data.get("workers", [])
502508

503-
except Exception:
504-
pass
509+
except Exception as e:
510+
# Log error for debugging
511+
if hasattr(self.arbiter, 'log') and self.arbiter.log:
512+
self.arbiter.log.debug("Failed to query dirty workers: %s", e)
505513

506514
return []
507515

gunicorn/dirty/protocol.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,21 @@ def encode_end(request_id: int) -> bytes:
277277
header = BinaryProtocol.encode_header(MSG_TYPE_END, request_id, 0)
278278
return header
279279

280+
@staticmethod
281+
def encode_status(request_id: int) -> bytes:
282+
"""
283+
Encode a status query message.
284+
285+
Args:
286+
request_id: Request identifier
287+
288+
Returns:
289+
bytes: Complete message (header + empty payload)
290+
"""
291+
# Status query has empty payload
292+
header = BinaryProtocol.encode_header(MSG_TYPE_STATUS, request_id, 0)
293+
return header
294+
280295
@staticmethod
281296
def encode_stash(request_id: int, op: int, table: str,
282297
key=None, value=None, pattern=None) -> bytes:
@@ -586,6 +601,8 @@ def _encode_from_dict(message: dict) -> bytes:
586601
message.get("value"),
587602
message.get("pattern")
588603
)
604+
elif msg_type == MSG_TYPE_STATUS:
605+
return BinaryProtocol.encode_status(request_id)
589606
else:
590607
raise DirtyProtocolError(f"Unhandled message type: {msg_type}")
591608

0 commit comments

Comments
 (0)