Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
c20b19d0
Commit
c20b19d0
authored
Sep 22, 2015
by
Craig Tiller
Browse files
Options
Downloads
Patches
Plain Diff
better logging
parent
99b65f22
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/run_tests/port_server.py
+7
-4
7 additions, 4 deletions
tools/run_tests/port_server.py
with
7 additions
and
4 deletions
tools/run_tests/port_server.py
+
7
−
4
View file @
c20b19d0
...
@@ -52,7 +52,7 @@ with open(__file__) as f:
...
@@ -52,7 +52,7 @@ with open(__file__) as f:
_MY_VERSION
=
hashlib
.
sha1
(
f
.
read
()).
hexdigest
()
_MY_VERSION
=
hashlib
.
sha1
(
f
.
read
()).
hexdigest
()
def
refill_pool
(
max_timeout
):
def
refill_pool
(
max_timeout
,
req
):
"""
Scan for ports not marked for being in use
"""
"""
Scan for ports not marked for being in use
"""
for
i
in
range
(
1025
,
32767
):
for
i
in
range
(
1025
,
32767
):
if
len
(
pool
)
>
100
:
break
if
len
(
pool
)
>
100
:
break
...
@@ -60,11 +60,13 @@ def refill_pool(max_timeout):
...
@@ -60,11 +60,13 @@ def refill_pool(max_timeout):
age
=
time
.
time
()
-
in_use
[
i
]
age
=
time
.
time
()
-
in_use
[
i
]
if
age
<
max_timeout
:
if
age
<
max_timeout
:
continue
continue
req
.
log_message
(
"
kill old request %d
"
%
i
)
del
in_use
[
i
]
del
in_use
[
i
]
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
s
.
setsockopt
(
socket
.
SOL_SOCKET
,
socket
.
SO_REUSEADDR
,
1
)
try
:
try
:
s
.
bind
((
'
localhost
'
,
i
))
s
.
bind
((
'
localhost
'
,
i
))
req
.
log_message
(
"
found available port %d
"
%
i
)
pool
.
append
(
i
)
pool
.
append
(
i
)
except
:
except
:
pass
# we really don't care about failures
pass
# we really don't care about failures
...
@@ -72,13 +74,14 @@ def refill_pool(max_timeout):
...
@@ -72,13 +74,14 @@ def refill_pool(max_timeout):
s
.
close
()
s
.
close
()
def
allocate_port
():
def
allocate_port
(
req
):
global
pool
global
pool
global
in_use
global
in_use
max_timeout
=
600
max_timeout
=
600
while
not
pool
:
while
not
pool
:
refill_pool
(
max_timeout
)
refill_pool
(
max_timeout
,
req
)
if
not
pool
:
if
not
pool
:
req
.
log_message
(
"
failed to find ports: retrying soon
"
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
max_timeout
/=
2
max_timeout
/=
2
port
=
pool
[
0
]
port
=
pool
[
0
]
...
@@ -100,7 +103,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
...
@@ -100,7 +103,7 @@ class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
self
.
send_response
(
200
)
self
.
send_response
(
200
)
self
.
send_header
(
'
Content-Type
'
,
'
text/plain
'
)
self
.
send_header
(
'
Content-Type
'
,
'
text/plain
'
)
self
.
end_headers
()
self
.
end_headers
()
p
=
allocate_port
()
p
=
allocate_port
(
self
)
self
.
log_message
(
'
allocated port %d
'
%
p
)
self
.
log_message
(
'
allocated port %d
'
%
p
)
self
.
wfile
.
write
(
'
%d
'
%
p
)
self
.
wfile
.
write
(
'
%d
'
%
p
)
elif
self
.
path
[
0
:
6
]
==
'
/drop/
'
:
elif
self
.
path
[
0
:
6
]
==
'
/drop/
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment