Skip to content

Commit

Permalink
fix(api): remove protocol file size limit and ack immediately (#4006)
Browse files Browse the repository at this point in the history
* fix(api): remove protocol file size limit and ack immediately. Fixes #3998
  • Loading branch information
btmorr authored Sep 9, 2019
1 parent 6c60457 commit 2a82724
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
18 changes: 4 additions & 14 deletions api/src/opentrons/server/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,9 @@ def send_worker(self, socket):

def task_done(future):
try:
result = future.result()
future.result()
except Exception:
log.exception("send_task for socket {} threw:".format(_id))
else:
log.info('send_task for socket {} result: {}'.format(
_id, result))
log.debug('Send task for {} finished'.format(_id))

async def send_task(socket, queue):
while True:
Expand Down Expand Up @@ -140,24 +136,20 @@ def task_done(future):
traceback.format_exc())
)

client = web.WebSocketResponse()
client = web.WebSocketResponse(max_msg_size=0)
client_id = id(client)

# upgrade to Websockets
await client.prepare(request)

log.info('Opening Websocket {0}'.format(id(client)))
log.debug('Tasks: {0}'.format(self.tasks))
log.debug('Clients: {0}'.format(self.clients))

try:
log.debug('Sending root info to {0}'.format(client_id))
await client.send_json({
'$': {'type': CONTROL_MESSAGE, 'monitor': True},
'root': self.call_and_serialize(lambda: self.root),
'type': self.call_and_serialize(lambda: type(self.root))
})
log.debug('Root info sent to {0}'.format(client_id))
except Exception:
log.exception('While sending root info to {0}'.format(client_id))

Expand Down Expand Up @@ -241,11 +233,11 @@ async def process(self, message):
_id = id(self.system)

try:
self.send_ack(token)
func = self.build_call(
_id=_id,
name=data.get('name'),
args=data.get('args', []))
self.send_ack(token)
except Exception as e:
log.exception("Exception during rpc.Server.process:")
error = '{0}: {1}'.format(e.__class__.__name__, e)
Expand All @@ -258,7 +250,7 @@ async def process(self, message):
'WebSocket connection closed unexpectedly: {0}'.format(
message))
else:
log.warning('Unhanled WSMsgType: {0}'.format(message.type))
log.warning('Unhandled WSMsgType: {0}'.format(message.type))
except Exception:
log.exception('Error while processing request')

Expand All @@ -274,7 +266,6 @@ def call_and_serialize(self, func, max_depth=0):
async def make_call(self, func, token):
response = {'$': {'type': CALL_RESULT_MESSAGE, 'token': token}}
try:
log.info(f"RPC call: {func} begins")
call_result = await self.loop.run_in_executor(
self.executor, self.call_and_serialize, func)
response['$']['status'] = 'success'
Expand Down Expand Up @@ -306,7 +297,6 @@ async def make_call(self, func, token):
'traceback': trace
}
finally:
log.info(f"RPC call: {func} ends")
response['data'] = call_result
return response

Expand Down
5 changes: 5 additions & 0 deletions api/tests/opentrons/server/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ async def test_exception_during_call(session):
await session.socket.receive_json()
await session.call()
res = await session.socket.receive_json()
assert res.pop('$') == {
'type': rpc.CALL_ACK_MESSAGE,
'token': session.token
}
res = await session.socket.receive_json()
assert res.pop('$') == {
'type': rpc.CALL_NACK_MESSAGE,
'token': session.token
Expand Down
2 changes: 1 addition & 1 deletion app/src/robot/api-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function apiClientMiddleware() {
action.error === true ? action.payload : action.payload.error

if (error) {
log.warn('Error response from robot', { action })
log.warn('Error response from robot', { actionType: action.type })
if (error.traceback) log.warn(error.traceback)
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/rpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class RpcContext extends EventEmitter {
}

// cache required metadata from call results
// filter type field from type object to avoid getting unecessary types
// filter type field from type object to avoid getting unnecessary types
_cacheCallResultMetadata(resultData) {
if (!resultData || !resultData.i) {
return
Expand Down

0 comments on commit 2a82724

Please sign in to comment.