8000 Merge pull request #55 from kvikas/master · shamrin/client_python@1b88cd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b88cd0

Browse files
committed
Merge pull request prometheus#55 from kvikas/master
Closing open socket in instance_ip_grouping_key()
2 parents c67b1e1 + 6269b8f commit 1b88cd0

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

prometheus_client/exposition.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import socket
77
import time
88
import threading
9+
from contextlib import closing
910

1011
from . import core
1112
try:
@@ -125,6 +126,6 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout):
125126

126127
def instance_ip_grouping_key():
127128
'''Grouping key with instance set to the IP Address of this host.'''
128-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
129-
s.connect(('localhost', 0))
130-
return {'instance': s.getsockname()[0]}
129+
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s:
130+
s.connect(('localhost', 0))
131+
return {'instance': s.getsockname()[0]}

0 commit comments

Comments
 (0)
0