-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection lost on await writer.drain() #67
Comments
This program though seems to work; import struct
import asyncio
import os
os.environ["PYTHONASYNCIODEBUG"] = "1"
loop = asyncio.get_event_loop()
async def client():
reader, writer = await asyncio.open_connection("35.173.6.94", 80, loop=loop)
print("\n connected to localhost:9881")
while True:
req = b"hello"
writer.write(req)
print("writer.transport._conn_lost", writer.transport._conn_lost)
if writer.transport._conn_lost:
writer.close()
reader, writer = await asyncio.open_connection("35.173.6.94", 80, loop=loop)
await writer.drain()
# import pdb
# pdb.set_trace()
print("\nsent request\n")
data = await reader.read(2)
print("\n\nread:\n")
print(data)
loop.run_until_complete(client()) ie this part seems to be key: # Do write, then check if connection is lost just before calling drain
writer.write(req)
print("writer.transport._conn_lost", writer.transport._conn_lost)
if writer.transport._conn_lost:
writer.close()
reader, writer = await asyncio.open_connection("35.173.6.94", 80, loop=loop)
await writer.drain() The program works and stays up longer than the previous one. writer.transport._conn_lost 0
Executing <Handle <TaskWakeupMethWrapper object at 0x10eed4d98>(<Future finis...events.py:377>) created at /usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/streams.py:182> took 0.371 seconds
Traceback (most recent call last):
File "smpp/debug.py", line 34, in <module>
loop.run_until_complete(client())
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
return future.result()
File "smpp/debug.py", line 22, in client
await writer.drain()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/streams.py", line 348, in drain
await self._protocol._drain_helper()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/streams.py", line 209, in _drain_helper
await waiter
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/selector_events.py", line 891, in _write_ready
n = self._sock.send(self._buffer)
BrokenPipeError: [Errno 32] Broken pipe |
Applied to body = b""
command_length = 16 + len(body) # 16 is for headers
command_id = cli.command_ids["enquire_link"]
command_status = 0x00000000
sequence_number = cli.sequence_generator.next_sequence()
header = struct.pack(">IIII", command_length, command_id, command_status, sequence_number)
full_pdu = header + body
loop.run_until_complete(
cli.send_data(smpp_event="enquire_link", msg=full_pdu, correlation_id="correlation_id3")
) error: Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/local/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/site-packages/naz/client.py", line 866, in send_data
await self.writer.drain()
File "/usr/local/lib/python3.6/asyncio/streams.py", line 339, in drain
yield from self._protocol._drain_helper()
File "/usr/local/lib/python3.6/asyncio/streams.py", line 210, in _drain_helper
raise ConnectionResetError('Connection lost')
ConnectionResetError: Connection lost see the culprit line; Line 866 in f2e8312
|
to TRY and manually fix the issue with ### this alone with NO `cli.tranceiver_bind()`
reader, writer = loop.run_until_complete(cli.connect())
### make SURE the session state is the right one.
cli.current_session_state = "BOUND_TRX"
## send `enquire_link`
loop.run_until_complete(
cli.send_data(smpp_event="enquire_link", msg=full_pdu, correlation_id="correlation_id3")
)
## read `enquire_link_resp` and print it
full_enquire_link_resp_pdu_data = receive_data()
parsed_enquire_link_resp = parse_response_pdu(full_enquire_link_resp_pdu_data)
print("\n parsed_enquire_link_resp: \n")
print(parsed_enquire_link_resp) prints {
'correlation_id': None,
'command_id': 2147483669,
'command_status': 4,
'smpp_event': 'enquire_link_resp',
'command_status_name': 'ESME_RINVBNDSTS',
'command_status_value': CommandStatus(code=4, description='Incorrect BIND Status for given command'),
'command_status_code': 4,
'command_status_value_description': 'Incorrect BIND Status for given command'
} Inference:
ref:
|
This manual fix, fixes that issue: ### connect
reader, writer = loop.run_until_complete(cli.connect())
### send bind_transceiver
loop.run_until_complete(
cli.send_data(smpp_event="bind_transceiver", msg=full_pdu, correlation_id="correlation_id1")
)
### read bind_transceiver_resp
full_tranceiver_bind_resp_pdu_data = receive_data()
parsed_tranceiver_bind_resp = parse_response_pdu(full_tranceiver_bind_resp_pdu_data)
## send `enquire_link`
loop.run_until_complete(
cli.send_data(smpp_event="enquire_link", msg=full_pdu, correlation_id="correlation_id3")
)
## read `enquire_link_resp` and print it
full_enquire_link_resp_pdu_data = receive_data()
parsed_enquire_link_resp = parse_response_pdu(full_enquire_link_resp_pdu_data)
print("\n parsed_enquire_link_resp: \n")
print(parsed_enquire_link_resp) prints {
'correlation_id': None,
'command_id': 2147483669,
'command_status': 0,
'smpp_event': 'enquire_link_resp',
'command_status_name': 'ESME_ROK',
'command_status_value': CommandStatus(code=0, description='Success'),
'command_status_code': 0,
'command_status_value_description': 'Success'
} |
We need to continuously check if connection is broken(how??, maybe
We should also tighten up the session state (and their transitions) -> #52 |
workaround: One reason why you may experience Connection lost errors is because of session timers[1][2]. One way to workaround this, is to set a very low import asyncio
import naz
loop = asyncio.get_event_loop()
outboundqueue = naz.q.SimpleOutboundQueue(maxsize=1000, loop=loop)
cli = naz.Client(
async_loop=loop,
smsc_host="127.0.0.1",
smsc_port=2775,
system_id="smppclient1",
password="password",
enquire_link_interval=5,
) or if using the {
"smsc_host": "127.0.0.1",
"smsc_port": 5004,
"system_id": "SomeID",
"password": "somePassword",
"enquire_link_interval": 5
} where the value you chose for That way, the ref:
|
How to reproduce, with the current head at;
|
What: - Introduce a configurable timeout when trying to connect to SMSC - Try and detect when the connection to SMSC is disconnected and attempt to re-connect & re-bind - bugfix; `asyncio.streams.StreamWriter.drain` should not be called concurrently by multiple coroutines[1] - when shutting down, `naz` now tries to make sure that write buffers are properly flushed[2][3] Why: - Make `naz` more failure tolerant - Fixes: #67 - Fixes: #114 - Fixes: #116 - Fixes: #117 - Fixes: #120 References: 1. https://bugs.python.org/issue29930 2. https://vorpus.org/blog/some-thoughts-on-asynchronous-api-design-in-a-post-asyncawait-world/ 3. aio-libs/aiohttp#1369
This program
produces the error:
The text was updated successfully, but these errors were encountered: