Overwriting socket data / not waiting for a response
See original GitHub issueDiscovered this issue when working on a separate project that depends on TuyAPI.
(I believe this may be the root cause of https://github.com/codetheweb/tuyapi/issues/158 and https://github.com/codetheweb/tuyapi/issues/103.)
I added a condition to the data event handler for the socket that checks if the parsed and returned data is an object; if not it would throw an error. After adding this, tests started failing.
I discovered that on a fast enough machine (and testing against a local stub) it’s possible to overwrite data sent to the socket by calling .set()
and/or .get()
quickly after each other. Data has already been being overwritten in the test suite, but it wasn’t caught because I didn’t add a check to see if the returned data was an object or not.
For instance, running the test suite generated this beautiful packet:
000055aa000000000000000a000000607b226465764964223a223232333235313836646234613232313764633865222c2267774964223a223232333235313836646234613232313764633865222c22647073223a7b2231223a747275652c2232223a747275657d7d000000000000aa55000055aa000000000000000a000000617b226465764964223a223232333235313836646234613232313764633865222c2267774964223a223232333235313836646234613232313764633865222c22647073223a7b2231223a747275652c2232223a66616c73657d7d000000000000aa55000055aa000000000000000a000000617b226465764964223a223232333235313836646234613232313764633865222c2267774964223a223232333235313836646234613232313764633865222c22647073223a7b2231223a747275652c2232223a66616c73657d7d000000000000aa55
Obviously invalid. I took a stab at implementing a function queue system, but it’s not working.
Thoughts @tjfontaine @kueblc @unparagoned?
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
@peterjuras it’s not quite ready yet; had some issues merging it last night and ran out of time to fix it. I’ll ping you when it’s published and ready. 😃
PR that tentatively fixes it should be merged by the end of the week @peterjuras.