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

Attempting to fix 738 #886

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

geoffoxholm
Copy link

@geoffoxholm geoffoxholm commented Mar 29, 2024

I'm trying to fix #738.

It looks like some apps (maybe just "Audible" at the moment) have a very rigid interpretation of the connection handshake, and abandon it if messages come out-of-order.

I'd love any feedback to help move this forward. I can step into the debugger, do whatever is needed to figure out how to fix the issue, though I'm new to the pychromecast repo.

@geoffoxholm geoffoxholm changed the title Users/geoff/audible debug Fix for 738 Mar 29, 2024
@geoffoxholm geoffoxholm changed the title Fix for 738 Attempting to fix for 738 Mar 29, 2024
@geoffoxholm geoffoxholm changed the title Attempting to fix for 738 Attempting to fix 738 Mar 29, 2024
@geoffoxholm
Copy link
Author

I would appreciate some feedback on this. Is there a better approach I could try? Any tips would be appreciated, I'll give it a serious try.

pyproject.toml Outdated Show resolved Hide resolved
Comment on lines +492 to +495
# When a new cast status is received, give Audible time to load
if status.app_id == "25456794":
self.logger.debug("Detected Audible connection. Sleeping for 1s")
time.sleep(1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really OK way to fix a race. Is there another message we can wait for instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure. any ideas you have, or example code you can point me to? i'll try whatever i can.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #738 talks about the Sirius XM app misbehaving, but your comment in the PR talks about Audible. Could you clarify the relationship between the two apps? Or are they the same?

Also, after going through the comments in #738, it's not fully clear to me what pychromecast does which offends the app so much that it terminates, only that adding a delay fixes the problem.

Have you been able to determine how the delay fixes it?

If you run pychromecast with debug enabled, it will dump out all messages sent to and received from the pychromecast, have you done that?

Also, I'm not sure how you've been debugging. But if you want a simple isolated test case, maybe this example script is enough to trigger (and debug) the problem:

python3 -m examples.simple_listener_example --cast 'Living room' --show-debug

Copy link
Collaborator

@emontnemery emontnemery Aug 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, there's already a comment in #738 about using the simple listener example to trigger the problem: #738 (comment)

If you could do that, but with the updated syntax as in my previous comment, both with and without your workaround, that would be really useful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git switch master
python3 -m examples.simple_listener_example --cast 'Garage speakers' --show-debug > workspace/master.std.txt 2> workspace/master.err.txt

master.err.txt
master.std.txt

git switch geoffoxholm:users/geoff/audible_debug
python3 -m examples.simple_listener_example --cast 'Garage speakers' --show-debug > workspace/patch.std.txt 2> workspace/patch.err.txt

patch.err.txt
patch.std.txt

Copy link
Collaborator

@emontnemery emontnemery Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a jump in requestId in messages sent by pychromecast to the device which I can't explain. We only increment the requestId when calculating it here:

request_id = self._gen_request_id()
data[REQUEST_ID] = request_id

Have you removed any lines from the logs?

Edit: Maybe it's ping messages being omitted from the log

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be sure, could you change here to log also the pings, both on master and your patch branch, and collect new logs:

# Log all messages except heartbeat
if msg.namespace != NS_HEARTBEAT:
self.logger.debug(
"[%s(%s):%s] Sending: %s",
self.fn or "",
self.host,
self.port,
_message_to_string(msg, data),
)

# debug messages
if message.namespace != NS_HEARTBEAT:
self.logger.debug(
"[%s(%s):%s] Received: %s",
self.fn or "",
self.host,
self.port,
_message_to_string(message, data),
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git switch master
git pull
# make edits
git diff > workspace/master.diff.txt
python3 -m examples.simple_listener_example --cast 'Garage speakers' --show-debug > workspace/master.std.txt 2> workspace/master.err.txt

master.diff.txt
master.err.txt
master.std.txt

git stash # stash edits
git switch users/geoff/audible_debug 
git stash pop # pop edits
git diff master > workspace/branch.diff.txt
python3 -m examples.simple_listener_example --cast 'Garage speakers' --show-debug > workspace/branch.std.txt 2> workspace/branch.err.txt

branch.diff.txt
branch.err.txt
branch.std.txt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #738 talks about the Sirius XM app misbehaving, but your comment in the PR talks about Audible. Could you clarify the relationship between the two apps? Or are they the same?

They are different apps. In the end the issue with Sirius XM was "fixed" (avoided) when the app was redesigned. It seems the Audible app has a similar pathology to the one that was present in the Sirius XM app, but no longer is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SiriusXM/Chromecast Casting Issue
3 participants