xpra icon
Bug tracker and wiki

Opened 4 years ago

Closed 5 months ago

Last modified 7 weeks ago

#540 closed enhancement (fixed)

handle connection issues, session events, network drop outs, power events, etc

Reported by: Antoine Martin Owned by: J. Max Mena
Priority: minor Milestone: 2.3
Component: core Version:
Keywords: Cc:

Description (last modified by Antoine Martin)

Follow up from #492, greater scope than #401 and #493.

  • we should register for notification from the OS's network events, so we don't try to send packets if the network is down, and so we can re-connect if needed once the network is back up (was #493)
  • we should probably handle session logout or shutdown events and disconnect more gracefully from the server
  • we should probably also handle lower power states better, so that if the screen is being dimmed due to lack of activity, then we can slow down the refresh rate too (if not pause it completely)
  • detect screensaver activation, and go to suspend mode
    • for win32: *win32gui.SystemParametersInfo(win32con.SPI_GETSCREENSAVERRUNNING, None, 0) gives you the screensaver state
      • properly using session events: http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html track session events
    • X11: X11 idle time and focused window in Python
  • it may also be useful to have those same event hooks on the server side: knowing that something is broken with the network would be useful in the logs and we could prevent unnecessary/unhelpful changes to speed,quality and batch settings when network problem occur
  • optional: when new interfaces come up, do we want to start publishing our mdns record on them?
  • if the client suspends then resumes, maybe we want to keep the connection alive longer (from #492):
    2014-03-20 13:42:21,933 system is suspending
    2014-03-20 13:42:24,628 server is not responding, drawing spinners over the windows
    2014-03-20 13:43:40,279 system resumed, was suspended for 0:01:18
    2014-03-20 13:43:40,358 WM_TIMECHANGE: time change event: 0 / 0
    2014-03-20 13:43:40,390 server ping timeout - waited 60 seconds without a response
    2014-03-20 13:43:41,920 Connection lost
    

In this case, the sleep was longer than 60 seconds, but if the TCP connection can be kept alive, why not keep it? (just suspend most of the work on the server until the underlying TCP connection breaks?)

Some links:

Change History (24)

comment:1 Changed 4 years ago by Antoine Martin

Description: modified (diff)

comment:2 Changed 4 years ago by Antoine Martin

Milestone: 0.130.14

comment:3 Changed 4 years ago by Antoine Martin

Description: modified (diff)
Owner: changed from Antoine Martin to Antoine Martin
Status: newassigned

comment:4 Changed 3 years ago by Antoine Martin

Milestone: 0.15future

re-scheduling, see also #978

Last edited 3 years ago by Antoine Martin (previous) (diff)

comment:5 Changed 3 years ago by Antoine Martin

Milestone: future0.17

comment:6 Changed 2 years ago by Antoine Martin

Milestone: 0.171.0

comment:7 Changed 2 years ago by Antoine Martin

For win32, found this: Waiting on an event when rendering is unnecessary in DXGI.
These two functions are Windows 8 and Platform Update for Windows 7 only (whatever that means):

For OSX, the power event handler is broken and causes crashes (now disabled): #924 / #1137.

Last edited 2 years ago by Antoine Martin (previous) (diff)

comment:8 Changed 2 years ago by Antoine Martin

Milestone: 1.01.1

Milestone renamed

comment:9 Changed 2 years ago by Antoine Martin

Milestone: 1.12.0

Milestone renamed

comment:10 Changed 2 years ago by Antoine Martin

For OSX, this function may be useful: CGDisplayIsAsleep: Returns a Boolean value indicating whether a display is sleeping (and is therefore not drawable.), but there doesn't seem to be any notifications for this one, so we would need to poll for it regularly.

comment:11 Changed 23 months ago by Antoine Martin

Milestone: 2.03.0

Related to #999 and #401

Last edited 18 months ago by Antoine Martin (previous) (diff)

comment:12 Changed 18 months ago by Antoine Martin

Milestone: 3.02.1

comment:13 Changed 14 months ago by Antoine Martin

Milestone: 2.12.2

re-scheduling

comment:14 Changed 12 months ago by Antoine Martin

See also ticket:1581#comment:1, the browser API can expose some network information.

comment:15 Changed 11 months ago by Antoine Martin

r16825 exposes the socket interface link speed to the server, unlike the values we get from the browser the values we get here do make sense. (no idea how chrome gets it so wrong: see ticket:1581#comment:3)

ie with 100Mbps LAN connection:

$ xpra info | grep connection-data.speed
client.connection-data.speed=100000000

Caveats:

  • not implemented for macos or win32 yet
  • does not detect changes in configuration yet (ie: network manager dbus API?)
  • server should also expose it? (not sure why it doesn't)
Last edited 11 months ago by Antoine Martin (previous) (diff)

comment:16 Changed 10 months ago by Antoine Martin

As of r17246 (client) and r17247 (server), 80% of the network interface speed is used as bandwidth-limit (#417).

This will do for this release.

On win32, looks like we can get the network adapter's speed from MSFT_NetAdapter (windows 8), Win32_NetworkAdapter (windows 7)
Something like this: Win32_NetworkAdapter - WMI sample in Python but without using python-wmi... (more tricky)

comment:17 Changed 10 months ago by Antoine Martin

Milestone: 2.22.3

comment:18 Changed 7 months ago by Antoine Martin

See also #619

comment:19 Changed 7 months ago by Antoine Martin

macos display-is-asleep detection added in r18239

Still TODO:

Last edited 7 months ago by Antoine Martin (previous) (diff)

comment:20 Changed 7 months ago by Antoine Martin

Why is it such a mess on a linux desktop? We have both org.freedesktop.ScreenSaver and org.gnome.ScreenSaver (ignoring what KDE does for now..), you would guess that the former would be the new more standardized name and would be an alias for the other one, but no: only the latter one gives you signals on a gnome-shell desktop (..).
Then to make things worse, triggering the screensaver with gnome-screensaver-command -a fires the ActiveChanged signal, but seemingly with the wrong value, and only once instead of twice (activate then deactivate). There will not be a "year of the Linux desktop", give up already.

win32 already had events for desktop lock and unlock since r10762 (see #901), we now add polling of screensaver status in r18242. (using the ISensLogon event interface directly using ctypes would be hard)

Last edited 7 months ago by Antoine Martin (previous) (diff)

comment:21 Changed 7 months ago by Antoine Martin

As for getting network device information on win32, using wmi seemed like the right way of going about it, except we don't have wmi bindings with ctypes so we have to use the long winded way (as per ticket:173#comment:25) and then comtypes blows up:

from comtypes.client import CreateObject
o=CreateObject('WbemScripting.SWbemLocator')
s=o.ConnectServer('.', 'root\\cimv2')
res=s.ExecQuery('SELECT * FROM MSFT_NetAdapter');
print(res[0])
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:/msys32/mingw32/lib/python2.7/site-packages/comtypes-1.1.4-py2.7.egg/comtypes/__init__.py", line 380, in __getitem__
    result = self.Item(*args)
ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>: unicode string expected instead of int instance

Even if it did work, it's not clear to me how we would be able to identify the network card that we are interested in ("GUID"? but which one is in use?). The equivalent wmic output for Win32_NetworkAdapter is not very helpful either:

$ wmic path Win32_NetworkAdapter
AdapterType     AdapterTypeId  AutoSense  Availability  Caption                                          ConfigManagerErrorCode  ConfigManagerUserConfig  CreationClassName     Description                           DeviceID  ErrorCleared  ErrorDescription  GUID                                    Index  InstallDate  Installed  InterfaceIndex  LastErrorCode  MACAddress         Manufacturer       MaxNumberControlled  MaxSpeed  Name                                  NetConnectionID        NetConnectionStatus  NetEnabled  NetworkAddresses  PermanentAddress  PhysicalAdapter  PNPDeviceID                                                   PowerManagementCapabilities  PowerManagementSupported  ProductName                           ServiceName   Speed       Status  StatusInfo  SystemCreationClassName  SystemName    TimeOfLastReset
                                          3             [00000000] WAN Miniport (SSTP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (SSTP)                   0                                                                                 0                   TRUE       2                                                 Microsoft          0                              WAN Miniport (SSTP)                                                                                                               FALSE            ROOT\MS_SSTPMINIPORT\0000                                                                  FALSE                     WAN Miniport (SSTP)                   RasSstp                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000001] WAN Miniport (IKEv2)                  0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IKEv2)                  1                                                                                 1                   TRUE       10                                                Microsoft          0                              WAN Miniport (IKEv2)                                                                                                              FALSE            ROOT\MS_AGILEVPNMINIPORT\0000                                                              FALSE                     WAN Miniport (IKEv2)                  RasAgileVpn                                   Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000002] WAN Miniport (L2TP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (L2TP)                   2                                                                                 2                   TRUE       3                                                 Microsoft          0                              WAN Miniport (L2TP)                                                                                                               FALSE            ROOT\MS_L2TPMINIPORT\0000                                                                  FALSE                     WAN Miniport (L2TP)                   Rasl2tp                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000003] WAN Miniport (PPTP)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (PPTP)                   3                                                                                 3                   TRUE       4                                                 Microsoft          0                              WAN Miniport (PPTP)                                                                                                               FALSE            ROOT\MS_PPTPMINIPORT\0000                                                                  FALSE                     WAN Miniport (PPTP)                   PptpMiniport                                  Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000004] WAN Miniport (PPPOE)                  0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (PPPOE)                  4                                                                                 4                   TRUE       5                                                 Microsoft          0                              WAN Miniport (PPPOE)                                                                                                              FALSE            ROOT\MS_PPPOEMINIPORT\0000                                                                 FALSE                     WAN Miniport (PPPOE)                  RasPppoe                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000005] WAN Miniport (IPv6)                   0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IPv6)                   5                                                                                 5                   TRUE       6                                                 Microsoft          0                              WAN Miniport (IPv6)                                                                                                               FALSE            ROOT\MS_NDISWANIPV6\0000                                                                   FALSE                     WAN Miniport (IPv6)                   NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000006] WAN Miniport (Network Monitor)        0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (Network Monitor)        6                                                                                 6                   TRUE       7                                                 Microsoft          0                              WAN Miniport (Network Monitor)                                                                                                    FALSE            ROOT\MS_NDISWANBH\0000                                                                     FALSE                     WAN Miniport (Network Monitor)        NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000007] Intel(R) PRO/1000 MT Desktop Adapter  0                       FALSE                    Win32_NetworkAdapter  Intel(R) PRO/1000 MT Desktop Adapter  7                                         {97D5CC41-B8EA-4336-B147-F8227887A3A8}  7                   TRUE       11                             08:00:27:8B:8F:56  Intel              0                              Intel(R) PRO/1000 MT Desktop Adapter  Local Area Connection  2                    TRUE                                            TRUE             PCI\VEN_8086&DEV_100E&SUBSYS_001E8086&REV_02\3&267A616A&0&18                               FALSE                     Intel(R) PRO/1000 MT Desktop Adapter  E1G60         1000000000                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000008] WAN Miniport (IP)                     0                       FALSE                    Win32_NetworkAdapter  WAN Miniport (IP)                     8                                                                                 8                   TRUE       8                                                 Microsoft          0                              WAN Miniport (IP)                                                                                                                 FALSE            ROOT\MS_NDISWANIP\0000                                                                     FALSE                     WAN Miniport (IP)                     NdisWan                                       Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000009] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              9                                                                                 9                   TRUE       12                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0000                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel        100000                          Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
                                          3             [00000010] RAS Async Adapter                                                                      Win32_NetworkAdapter  RAS Async Adapter                     10                                                                                10                  TRUE       9                                                                    0                              RAS Async Adapter                                                                                                                 FALSE                                                                                                       FALSE                     RAS Async Adapter                                                                   Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000011] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              11                                                                                11                  TRUE       13                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0001                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel                                        Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000012] Microsoft Teredo Tunneling Adapter    0                       FALSE                    Win32_NetworkAdapter  Microsoft Teredo Tunneling Adapter    12                                                                                12                  TRUE       14                                                Microsoft          0                              Teredo Tunneling Pseudo-Interface                                                                                                 FALSE            ROOT\*TEREDO\0000                                                                          FALSE                     Microsoft Teredo Tunneling Adapter    tunnel        100000                          Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Tunnel          15                        3             [00000013] Microsoft ISATAP Adapter              0                       FALSE                    Win32_NetworkAdapter  Microsoft ISATAP Adapter              13                                                                                13                  TRUE       15                                                Microsoft          0                              Microsoft ISATAP Adapter                                                                                                          FALSE            ROOT\*ISATAP\0002                                                                          FALSE                     Microsoft ISATAP Adapter              tunnel                                        Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000014] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      14                                                                                14                  TRUE       19                             08:00:27:8B:8F:56  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0000                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000015] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      15                                                                                15                  TRUE       18                             42:21:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0001                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000016] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      16                                                                                16                  TRUE       17                             3E:C2:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0002                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420
Ethernet 802.3  0                         3             [00000017] NetLimiter Ndis Miniport Service      0                       FALSE                    Win32_NetworkAdapter  NetLimiter Ndis Miniport Service      17                                                                                17                  TRUE       16                             42:21:20:52:41:53  Locktime Software  0                              NetLimiter Ndis Miniport Service                                                                                                  FALSE            ROOT\NLNDISMP\0003                                                                         FALSE                     NetLimiter Ndis Miniport Service      NLNdisMP                                      Win32_ComputerSystem     WIN7PROX86VM  20180130203807.801655+420

What we know about:

$ ./Network_info.exe | head -n 7
Network interfaces found:
* {97D5CC41-B8EA-4336-B147-F8227887A3A8} (index=None)
* {E29AC6C2-7037-11DE-816D-806E6F6E6963} (index=None)
* {6EA7AA15-1A44-4AA4-AF09-3BBA667A284E} (index=None)
* {D054ED2E-6492-4002-BF0F-BDB357446D49} (index=None)
Gateways found:
* INET                            : [('192.168.1.1', '{97D5CC41-B8EA-4336-B147-F8227887A3A8}', True)]

Match the connection target with the network interface subnet? Fallback to gateway? Then find the "speed" from wmi..

Last edited 7 months ago by Antoine Martin (previous) (diff)

comment:22 Changed 5 months ago by Antoine Martin

Owner: changed from Antoine Martin to J. Max Mena
Status: assignednew

win32 support added in r18790.
We should now get accurate network interface speed on all platforms, except macos...
ie on win32 now:

$ ./Network_info.exe |& head -n 5
Network interfaces found:
* {97D5CC41-B8EA-4336-B147-F8227887A3A8} (index=None) (speed=1Gbps)
* {E29AC6C2-7037-11DE-816D-806E6F6E6963} (index=None)
* {6EA7AA15-1A44-4AA4-AF09-3BBA667A284E} (index=None)
* {D054ED2E-6492-4002-BF0F-BDB357446D49} (index=None)

(xpra/net/net_util.py doesn't show it on Linux - because we need an active connection to get the speed)

Or through xpra info (all supported platforms):

$ xpra info | grep connection-data.speed
client.connection-data.speed=100000000

As well as screensaver detection to slow down the screen refresh rate (just not on Linux..)

@maxmylyn: FYI, feel free to close.

Last edited 5 months ago by Antoine Martin (previous) (diff)

comment:23 Changed 5 months ago by J. Max Mena

Resolution: fixed
Status: newclosed

Noted and closing

comment:24 Changed 3 months ago by Antoine Martin

See also #1860, comtypes 32-bit error: #1899

Last edited 7 weeks ago by Antoine Martin (previous) (diff)
Note: See TracTickets for help on using tickets.