[serve] Better validation for arguments to client.start() (#14327)

This commit is contained in:
tchordia 2021-03-03 14:33:36 -08:00 committed by GitHub
parent 60a8b67488
commit e40dc3a3e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -211,7 +211,14 @@ class HTTPProxyActor:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
if hasattr(socket, "SO_REUSEPORT"):
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
sock.bind((self.host, self.port))
try:
sock.bind((self.host, self.port))
except OSError:
# The OS failed to bind a socket to the given host and port.
raise ValueError(
f"""Failed to bind Ray Serve HTTP proxy to '{self.host}:{self.port}'.
Please make sure your http-host and http-port are specified correctly.""")
# Note(simon): we have to use lower level uvicorn Config and Server
# class because we want to run the server as a coroutine. The only

View file

@ -162,7 +162,7 @@ def test_middleware():
def test_http_proxy_fail_loudly():
# Test that if the http server fail to start, serve.start should fail.
with pytest.raises(socket.gaierror):
with pytest.raises(ValueError):
serve.start(http_options={"host": "bad.ip.address"})
ray.shutdown()