Repository navigation
Commit 465527b
Emit App.modify_state deltas only to tokens a browser connected with (#7921)
* Do not emit to a shared state token in App.modify_state
Modifying a SharedState by its shared token (from an API route or a
background task) ended with emit_update to the shared token. No browser
connects with that token, so every call logged "Attempting to send delta
to disconnected client" even though the linked clients got the update
through the shared state fan-out.
Skip the emit when the modified state is the shared copy for that token,
which is the SharedState whose _linked_to is the token's ident. A client
token that is not connected still logs the warning.
Closes #7913
* Emit modify_state deltas only to tokens a browser connected with
A shared state token never has a socket, so App.modify_state now gates the
emit on the root state's rx_router_session.session_id, which the socket
connect records. This replaces the per-class _linked_to check: a connected
browser token that another client links to keeps its emit, a shared token
that no client linked to yet no longer warns, and the check no longer
depends on the class passed in the token.
* Emit modify_state deltas to connected tokens whose state expired
A state that expires while its browser stays connected comes back without
a session id. App.modify_state now also emits when the token manager has a
socket for the token, so that browser keeps getting out-of-band updates.
The test gets an expired-state case, docstrings on its helpers, and only
counts warnings from the reflex.app logger.
* Pin the modify_state emit test to the local token manager
With REFLEX_REDIS_URL set, EventNamespace creates a RedisTokenManager:
the disconnected token then logs no warning, and the socket records
the test links stay in redis and break test_redis_token_manager_enumerate_tokens.
* Suppress the disconnected client warning in modify_state
Add a suppress_warnings keyword to EventNamespace.emit_update and pass
it from App.modify_state, as suggested in review. emit_update already
looks up the socket of the token, so connected tokens still get the
emit and only the warning for a token without a socket is skipped. This
replaces the session id and connection check added to modify_state.
The modify_state emit test now checks the socket ids each update is
emitted to, that modify_state logs no warning for a token without a
socket, and that a regular emit_update to a disconnected token still
logs it.
---------
Co-authored-by: Farhan <www.mfarvirus@gmail.com>1 parent 810bbd2 commit 465527b
3 files changed
Lines changed: 120 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2379 | 2379 | | |
2380 | 2380 | | |
2381 | 2381 | | |
| 2382 | + | |
2382 | 2383 | | |
2383 | 2384 | | |
2384 | 2385 | | |
| |||
2819 | 2820 | | |
2820 | 2821 | | |
2821 | 2822 | | |
2822 | | - | |
| 2823 | + | |
| 2824 | + | |
| 2825 | + | |
2823 | 2826 | | |
2824 | 2827 | | |
2825 | 2828 | | |
2826 | 2829 | | |
2827 | 2830 | | |
| 2831 | + | |
| 2832 | + | |
2828 | 2833 | | |
2829 | 2834 | | |
2830 | 2835 | | |
| |||
2834 | 2839 | | |
2835 | 2840 | | |
2836 | 2841 | | |
2837 | | - | |
| 2842 | + | |
2838 | 2843 | | |
2839 | 2844 | | |
2840 | 2845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
103 | 104 | | |
104 | 105 | | |
105 | 106 | | |
106 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
4474 | 4479 | | |
4475 | 4480 | | |
4476 | 4481 | | |
4477 | | - | |
4478 | | - | |
4479 | | - | |
4480 | | - | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
4481 | 4487 | | |
4482 | 4488 | | |
4483 | 4489 | | |
| |||
4637 | 4643 | | |
4638 | 4644 | | |
4639 | 4645 | | |
| 4646 | + | |
| 4647 | + | |
| 4648 | + | |
| 4649 | + | |
| 4650 | + | |
| 4651 | + | |
| 4652 | + | |
| 4653 | + | |
| 4654 | + | |
| 4655 | + | |
| 4656 | + | |
| 4657 | + | |
| 4658 | + | |
| 4659 | + | |
| 4660 | + | |
| 4661 | + | |
| 4662 | + | |
| 4663 | + | |
| 4664 | + | |
| 4665 | + | |
| 4666 | + | |
| 4667 | + | |
| 4668 | + | |
| 4669 | + | |
| 4670 | + | |
| 4671 | + | |
| 4672 | + | |
| 4673 | + | |
| 4674 | + | |
| 4675 | + | |
| 4676 | + | |
| 4677 | + | |
| 4678 | + | |
| 4679 | + | |
| 4680 | + | |
| 4681 | + | |
| 4682 | + | |
| 4683 | + | |
| 4684 | + | |
| 4685 | + | |
| 4686 | + | |
| 4687 | + | |
| 4688 | + | |
| 4689 | + | |
| 4690 | + | |
| 4691 | + | |
| 4692 | + | |
| 4693 | + | |
| 4694 | + | |
| 4695 | + | |
| 4696 | + | |
| 4697 | + | |
| 4698 | + | |
| 4699 | + | |
| 4700 | + | |
| 4701 | + | |
| 4702 | + | |
| 4703 | + | |
| 4704 | + | |
| 4705 | + | |
| 4706 | + | |
| 4707 | + | |
| 4708 | + | |
| 4709 | + | |
| 4710 | + | |
| 4711 | + | |
| 4712 | + | |
| 4713 | + | |
| 4714 | + | |
| 4715 | + | |
| 4716 | + | |
| 4717 | + | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
| 4724 | + | |
| 4725 | + | |
| 4726 | + | |
| 4727 | + | |
| 4728 | + | |
| 4729 | + | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
| 4733 | + | |
| 4734 | + | |
| 4735 | + | |
| 4736 | + | |
| 4737 | + | |
| 4738 | + | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
4640 | 4747 | | |
4641 | 4748 | | |
4642 | 4749 | | |
| |||
0 commit comments