Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Connection Closed and Error Connection 33 (CA-4) #8

Open
kangbudz opened this issue Nov 14, 2019 · 10 comments · May be fixed by #25
Open

Connection Closed and Error Connection 33 (CA-4) #8

kangbudz opened this issue Nov 14, 2019 · 10 comments · May be fixed by #25

Comments

@kangbudz
Copy link

I have try this sample code for integration with Google IOT Core with IDF versi 3.3rc.
Device send receive command to GCP is no problem.
But when leave it in long time (more than 1 hours and no activity ), device disconnected and i got error log as below :

connection closed - reason 17!
ERROR!  Connection has failed reason 33

from iotc error lib, error 17 is IOTC_CONNECTION_RESET_BY_PEER_ERROR.

if anyone has similar issue, please advice for improvement. thank you

@projectgus projectgus changed the title Connection Closed and Error Connection 33 Connection Closed and Error Connection 33 (CA-4) Jan 1, 2020
@kangbudz
Copy link
Author

is there any information related this issue?
i have try latest version of google-iot-solution sample , and it is same result.
thanks

@tremblayraphael29
Copy link

Same problem for me!Does anyone have a solution?

@meltdown03
Copy link

Your JWT key expired, only lasts an hour. A workaround is to put a while(1) loop in the mqtt_task() function around everything except the vTaskdelete(NULL); That way when the IOTC task errors out, it shuts down and restarts by itself.

@benpeoples
Copy link

@meltdown03 That's a good workaround, but I think needs some sort of incremental backoff timer to keep from just spamming the server if it's a different issue.

Handling error 33 as a reauth would probably be the correct PR to implement.

@Gohith
Copy link

Gohith commented Sep 2, 2020

Hello Everyone !!!
I found that JWT is not encoded properly in base64. I copied jwt outcome and crosschecked in (https://jwt.io) and got signature error back.
@esp_team guys can you please look on this issue.

@supreetd21
Copy link
Collaborator

Hi @Gohith,
I tried printing & analyzing the generated JWT.
In my case, the token appears invalid to https://jwt.io but it decodes the data as expected and gives the warning -
Looks like your JWT payload is not encoded correctly using base64url (https://tools.ietf.org/html/rfc4648#section-5). Note that padding ("=") must be omitted as per https://tools.ietf.org/html/rfc7515#section-2

The warning is because of the redundant padding (the '=' signs at the end of the token) in the base 64 URL encoded JWT.
Google IoT communication works well with any of the tokens.

@robotjosh
Copy link

How is this bug not solved in over 1 year? This is not giving me confidence in this sdk.

@benpeoples
Copy link

benpeoples commented Jan 18, 2021

@robotjosh There does not seem to be a lot of effort at the google IOT solution. This isn't technically a bug, it's just that the example code doesn't handle expiring JWT.

Of note, there's a bug (I have not yet reported because I don't have enough details) that causes spurious crashes when the server disconnects you (generally when the server shuts down). Doesn't happen 100% of the time, but we have a few dozen devices out right now, and we're finding crashes in the IOT code in the coredumps. Oh, I did report it: #20

My workaround is to just use the JWT code to make the tokens and implement the rest using the stock mqtt library-- that appears to be super solid, it's this wrapper on the IOT that's having issues.

@robotjosh
Copy link

robotjosh commented Jan 18, 2021 via email

@benpeoples
Copy link

benpeoples commented Jan 18, 2021

I don't think so.

The JWT is used as the password to the MQTT server, and there isn't really a way to say "hey my password is this now" -- you can make the JWT timeout arbitrarily long and minimize how often the disconnections happen.

Here's the Google IOT documentation on refresh: https://cloud.google.com/iot/docs/how-tos/credentials/jwts#refreshing_jwts -- and all the examples are a disconnect-reconnect cycle.

@mostthingsweb mostthingsweb linked a pull request Mar 21, 2021 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants