osmo_trap2cgi.py: Don't recurse in ctrl_client()
Use a loop instead. Without it the script will eventually crash with a RecursionError. File "/usr/bin/osmo_trap2cgi.py", line 211, in conn_client await ctrl_client(proxy, reader, writer) File "/usr/bin/osmo_trap2cgi.py", line 202, in ctrl_client proxy.dispatch(wr, data) [...] File "/usr/bin/osmo_trap2cgi.py", line 202, in ctrl_client proxy.dispatch(wr, data) File "/usr/bin/osmo_trap2cgi.py", line 201, in ctrl_client [...] RecursionError: maximum recursion depth exceeded in comparison Change-Id: Ic909e371771f3056cb87e18793fd4225ffb90a2c Related: SYS#4399
This commit is contained in:
parent
f52d4a63d9
commit
ee9f2e211b
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ = "0.0.1" # bump this on every non-trivial change
|
__version__ = "0.0.2" # bump this on every non-trivial change
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import configparser, argparse, time, os, asyncio, aiohttp
|
import configparser, argparse, time, os, asyncio, aiohttp
|
||||||
|
@ -190,29 +190,32 @@ async def recon_reader(proxy, reader, num_bytes):
|
||||||
return await reader.readexactly(num_bytes)
|
return await reader.readexactly(num_bytes)
|
||||||
except asyncio.IncompleteReadError:
|
except asyncio.IncompleteReadError:
|
||||||
proxy.log.info('Failed to read %d bytes reconnecting to %s:%d...', num_bytes, proxy.ctrl_addr, proxy.ctrl_port)
|
proxy.log.info('Failed to read %d bytes reconnecting to %s:%d...', num_bytes, proxy.ctrl_addr, proxy.ctrl_port)
|
||||||
await conn_client(proxy)
|
raise
|
||||||
|
|
||||||
async def ctrl_client(proxy, rd, wr):
|
async def ctrl_client(proxy, rd, wr):
|
||||||
"""
|
"""
|
||||||
Recursively read CTRL stream and handle selected messages.
|
Read CTRL stream and handle selected messages.
|
||||||
"""
|
"""
|
||||||
header = await recon_reader(proxy, rd, 4)
|
while True:
|
||||||
data = await recon_reader(proxy, rd, get_ctrl_len(proxy, header))
|
header = await recon_reader(proxy, rd, 4)
|
||||||
proxy.dispatch(wr, data)
|
data = await recon_reader(proxy, rd, get_ctrl_len(proxy, header))
|
||||||
await ctrl_client(proxy, rd, wr)
|
proxy.dispatch(wr, data)
|
||||||
|
|
||||||
async def conn_client(proxy):
|
async def conn_client(proxy):
|
||||||
"""
|
"""
|
||||||
(Re)establish connection with CTRL server and pass Reader/Writer to CTRL handler.
|
(Re)establish connection with CTRL server and pass Reader/Writer to CTRL handler.
|
||||||
"""
|
"""
|
||||||
try:
|
while True:
|
||||||
reader, writer = await asyncio.open_connection(proxy.ctrl_addr, proxy.ctrl_port)
|
try:
|
||||||
proxy.log.info('Connected to %s:%d', proxy.ctrl_addr, proxy.ctrl_port)
|
reader, writer = await asyncio.open_connection(proxy.ctrl_addr, proxy.ctrl_port)
|
||||||
await ctrl_client(proxy, reader, writer)
|
proxy.log.info('Connected to %s:%d', proxy.ctrl_addr, proxy.ctrl_port)
|
||||||
except OSError as e:
|
await ctrl_client(proxy, reader, writer)
|
||||||
proxy.log.info('%s: %d seconds delayed retrying...', e, proxy.timeout)
|
except OSError as e:
|
||||||
await asyncio.sleep(proxy.timeout)
|
proxy.log.info('%s: %d seconds delayed retrying...', e, proxy.timeout)
|
||||||
await conn_client(proxy)
|
await asyncio.sleep(proxy.timeout)
|
||||||
|
except asyncio.IncompleteReadError:
|
||||||
|
pass
|
||||||
|
proxy.log.info('Reconnecting...')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue