Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit f5646cf

Browse files
author
Junchao Wu
committed
Treat protocolError and timeoutError for backoff approach
Raise exception to stop advertising for other exceptions
1 parent ab72454 commit f5646cf

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

tchannel/messages/error.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class ErrorMessage(BaseMessage):
6060
ErrorCode.unexpected: 'unexpected',
6161
ErrorCode.bad_request: 'bad request',
6262
ErrorCode.network_error: 'network error',
63+
ErrorCode.unhealthy: 'unhealthy error',
6364
ErrorCode.fatal: 'fatal protocol error'
6465
}
6566

tchannel/tornado/hyperbahn.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import json
2424
import logging
2525

26+
from ..errors import ProtocolError
27+
from ..errors import TimeoutError
28+
2629
import tornado.gen
2730
import tornado.ioloop
2831

@@ -86,7 +89,7 @@ def _register(attempt_counter=0):
8689
headers={'as': 'json'},
8790
attempt_times=1,
8891
)
89-
except Exception as e:
92+
except (ProtocolError, TimeoutError) as e:
9093
attempt_counter += 1
9194
log.error('Failed to register with Hyperbahn: %s', e)
9295
else:
@@ -95,14 +98,14 @@ def _register(attempt_counter=0):
9598
log.error('Failed to register with Hyperbahn: %s', response)
9699
else:
97100
attempt_counter = 0
98-
finally:
99-
delay_time = DEFAULT_ERROR_RETRY_TIMES[
100-
min(attempt_counter, len(DEFAULT_ERROR_RETRY_TIMES) - 1)
101-
]
102-
tornado.ioloop.IOLoop.current().call_later(
103-
delay=delay_time,
104-
callback=lambda: _register(attempt_counter),
105-
)
101+
102+
delay_time = DEFAULT_ERROR_RETRY_TIMES[
103+
min(attempt_counter, len(DEFAULT_ERROR_RETRY_TIMES) - 1)
104+
]
105+
tornado.ioloop.IOLoop.current().call_later(
106+
delay=delay_time,
107+
callback=lambda: _register(attempt_counter),
108+
)
106109

107110
return _register()
108111

tests/tornado/test_hyperbahn.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
# THE SOFTWARE.
2020

21-
from mock import patch
2221
import pytest
2322

2423
from tchannel.errors import ConnectionClosedError
@@ -61,6 +60,5 @@ def test_request():
6160
def test_register():
6261
channel = TChannel(name='test')
6362

64-
with patch('tchannel.tornado.hyperbahn.log') as mock_logger:
63+
with pytest.raises(ConnectionClosedError):
6564
yield hyperbahn.advertise(channel, 'foo', ['127.0.0.1:23000'])
66-
assert mock_logger.error.called

0 commit comments

Comments
 (0)