Skip to content
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

[Electron/LTE] devices drop Cloud connection every time user firmware opens and closes a TCP socket [ch34976] #1854

Merged
merged 1 commit into from Aug 1, 2019

Conversation

@technobly
Copy link
Member

commented Jul 13, 2019

Problem

LTE E-series R410 devices drop Cloud connection every time user firmware opens and closes a TCP socket. This does not appear to affect U260/U201/G350 devices.

Root cause

The timeout for the socket close command USOCL times out after 10s (has been this way since the first electron release). Sara R410M timeout of this command is 120 seconds, but that is likely only for TCP sockets since UDP sockets can be closed immediately. Sara U201/260/G350 timeout of this command is 1 second. If the TCP socket took more than 10 seconds to close, the USOCL command would timeout and allow the AT interface to be accessed by the next command, but it would not ready because it's still waiting for the socket close command to finish or timeout. If a following command happens to be a Particle Publish, Keep Alive Ping or Vitals Publish, these commands are blocked by the TCP socket closing and subsequently forces a teardown of the Cloud connection.

Solution

Timeouts will are adjusted so that if the socket is a TCP socket, the full 120 second timeout is respected. If it's a UDP socket, we will continue to optimize this value down to 10 seconds.

Steps to Test

Requires a TCP connection to a server that defaults to the Connection: keep-alive\r\n state, and closes slowly when TCPClient::stop() is called. This is not a common case, and at this time of writing only one customer server is known to behave this way and will be tested internally. If other public servers are noted with this issue, this PR will be updated with a test app that demonstrates this behavior and this test app will be added to the internal on-device tests.

Workaround for slowly closing TCP sockets

Add Connection: close\r\n to your request header. This should cause an immediate remote close of the socket from the server when all data has been sent by the server.

TEST=wiring/no_fixture

Review

Review non-whitespace changes: https://github.com/particle-iot/device-os/pull/1854/files?w=1

Test firmware for electron

electron-system-part1@1.3.0-rc.1+debug.pr1854.zip


Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA (Info here)
  • Problem and Solution clearly stated
  • Run unit/integration/application tests on device
  • Added documentation
  • Added to CHANGELOG.md after merging (add links to docs and issues)

  • [bugfix] [electron/LTE] devices drop Cloud connection every time user firmware opens and closes a TCP socket [ch34976] #1854

@technobly technobly added this to the 1.3.1-rc.1 milestone Jul 13, 2019

@technobly technobly requested a review from sergeuz Jul 13, 2019

@technobly technobly changed the title [Electron/LTE] devices lose cellular connection every time user firmware opens and closes a TCP socket [ch34976] [Electron/LTE] devices drop Cloud connection every time user firmware opens and closes a TCP socket [ch34976] Jul 16, 2019

@sergeuz
Copy link
Member

left a comment

Looks good 👍

@sergeuz sergeuz added ready to merge and removed needs review labels Jul 31, 2019

@technobly technobly force-pushed the fix/ch34976-tcp branch from 2b83af8 to 167b781 Aug 1, 2019

@technobly technobly merged commit 3bdf4c4 into develop Aug 1, 2019

2 checks passed

Codacy/PR Quality Review Up to standards. A positive pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@technobly technobly deleted the fix/ch34976-tcp branch Aug 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.