Bug 282153 - Networking::Connected emitted while the connection is not ready
Summary: Networking::Connected emitted while the connection is not ready
Status: RESOLVED UPSTREAM
Alias: None
Product: solid
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: Alex Fiestas
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-16 17:07 UTC by Matthias Fuchs
Modified: 2011-10-15 23:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Output upon plugging in the cable. (14.24 KB, text/plain)
2011-09-18 10:58 UTC, Matthias Fuchs
Details
Output when disconnected (14.24 KB, text/plain)
2011-09-20 21:30 UTC, Matthias Fuchs
Details
xsession-errors file (85.78 KB, application/octet-stream)
2011-09-21 08:31 UTC, Matthias Fuchs
Details
log (110.50 KB, application/x-gzip)
2011-09-26 20:53 UTC, Matthias Fuchs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Matthias Fuchs 2011-09-16 17:07:57 UTC
Version:           unspecified (using Devel) 
OS:                Linux

When I plug in my network cable instantly Solid::Networking::notifier() is emitted with "Solid::Networking::Connected" while the connection is actually not ready at that point.

Interestingly the plasma network manager reflects the none-readyness by displaying a kind of progress bar.

Reproducible: Didn't try

Steps to Reproduce:
I wanted to test if the comic dataengine reacts correctly to getting a connection, so I added some debug output to kdeplasma-addons/dataengines/comic/comic.cpp:ComicEngine::networkStatusChanged

1. unplug cable
2. plasmoidviewer comic
3. choose a comic and press ok
4. then after a while plug in the cable
5. instantly ComicEngine::networkStatusChanged is called with Solid::Networking::Connected


Expected Results:  
Solid::Networking::Connecting should have been emitted and then later on Solid::Networking::Connected
Comment 1 Lamarque V. Souza 2011-09-17 02:14:03 UTC
Which NM version and KDE SC do you use?

Are you connecting your slot to Solid::Networking::notifier() or org.kde.networkstatus? They use different backends, so I need to know which one you are using.

Can you monitor NM and see if its signals are being emmited at the right time? You can do it like this:

dbus-monitor --system "type='signal',sender='org.freedesktop.NetworkManager',interface='org.freedesktop.NetworkManager'"

wait for the "connecting" signal (State == 40):

signal sender=:1.0 -> dest=(null destination) serial=135662 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 40
      )
      dict entry(
         string "ActiveConnections"
         variant             array [
               object path "/org/freedesktop/NetworkManager/ActiveConnection/8"
            ]
      )
   ]
 
and then for the "connected" signal (State == 70):

signal sender=:1.0 -> dest=(null destination) serial=135679 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=StateChanged
   uint32 70
signal sender=:1.0 -> dest=(null destination) serial=135686 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 70
      )
   ]


It must be a few seconds gap between those two signals (unless your ethernet switch and card are too fast).
Comment 2 Matthias Fuchs 2011-09-18 10:58:32 UTC
Created attachment 63745 [details]
Output upon plugging in the cable.

NetworkManager 0.9.0

I connect to "Solid::Networking::notifier()".

I just tried and I instantly receive
"signal sender=:1.0 -> dest=(null destination) serial=580 path=/org/freedesktop/NetworkManager/Devices/0; interface=org.freedesktop.NetworkManager.Device.Wired; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 70
      )
   ]
"

So there is no noticeable gap inbetween.


Interestingly after some time (probably when the networkmanager plasmoid shows that it is connected) this gets emitted:

"signal sender=:1.0 -> dest=(null destination) serial=605 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 70
      )
   ]
"

Though the slot I connected to Solid::Networking::notifier() is not called again.
Comment 3 Lamarque V. Souza 2011-09-18 15:59:09 UTC
You are mixing the signals from org.freedesktop.NetworkManager.Device.Wired and  org.freedesktop.NetworkManager interfaces, they are different. 70 means NM_DEVICE_STATE_IP_CONFIG (dhcp client is running) for org.freedesktop.NetworkManager.Device.Wired and NM_STATE_CONNECTED_GLOBAL (fully connected) for org.freedesktop.NetworkManager. Take a look in /usr/include/NetworkManager/NetworkManager.h.

Anyway, the lines below from your log may explain what is happening:

signal sender=:1.0 -> dest=(null destination) serial=598 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=StateChanged
   uint32 70
signal sender=:1.0 -> dest=(null destination) serial=599 path=/org/freedesktop/NetworkManager/Devices/0; interface=org.freedesktop.NetworkManager.Device; member=StateChanged
   uint32 100
   uint32 70
   uint32 0
signal sender=:1.0 -> dest=(null destination) serial=604 path=/org/freedesktop/NetworkManager/Devices/0; interface=org.freedesktop.NetworkManager.Device.Wired; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 100
      )
      dict entry(
         string "Ip4Config"
         variant             object path "/org/freedesktop/NetworkManager/IP4Config/2"
      )
   ]
signal sender=:1.0 -> dest=(null destination) serial=605 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 70
      )
   ]

NetworkManager emits the org.freedesktop.NetworkManager's StateChanged signal before the org.freedesktop.NetworkManager.Device.Wired and org.freedesktop.NetworkManager's PropertiesChanged signals. Because of that Solid::Networking::notifier() emits the statusChanged signal before the wired interface emits its signal. Maybe that is the cause of your problem.

OBS: the plasmoid updates the tray icon by getting the status of the network interface that has the default route (so that it can change the icon to wifi, wired, phone, etc), not through statusChanged signal, so it does not suffer from this problem.

One solution is to change Solid::Networking::notifier()'s backend to use org.freedesktop.NetworkManager's PropertiesChanged signal instead of the StateChanged signal. I just do not know if the PropertiesChanged signal is emitted when NetworkManager stops, if not then we will have a problem.

Can you tell me if there is a considerable time gap between the signals:

signal sender=:1.0 -> dest=(null destination) serial=598 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=StateChanged
   uint32 70

and 

signal sender=:1.0 -> dest=(null destination) serial=605 path=/org/freedesktop/NetworkManager; interface=org.freedesktop.NetworkManager; member=PropertiesChanged
   array [
      dict entry(
         string "State"
         variant             uint32 70
      )
   ]
Comment 4 Matthias Fuchs 2011-09-18 21:08:45 UTC
Both are emitted roughly at the same time, i.e. once the plasmoid shows that a connection has been successfully created.
Comment 5 Lamarque V. Souza 2011-09-19 02:08:15 UTC
Enable debug messages using kdebugdialog (search for all network related debug outputs), execute:

solid-network query status
qdbus org.kde.kded /modules/networkstatus status
qdbus org.kde.kded /modules/networkstatus \
org.kde.Solid.Networking.Service.networks

before connecting. By the way, you use only NM, right?
Comment 6 Matthias Fuchs 2011-09-20 21:30:07 UTC
Created attachment 63805 [details]
Output when disconnected

As far as I know I only use NM.
Comment 7 Lamarque V. Souza 2011-09-20 21:43:02 UTC
(In reply to comment #6)
> Created an attachment (id=63805) [details]
> Output when disconnected
> 
> As far as I know I only use NM.

Sorry, I was not clear in my last post. I need you to send me your ~/.xsession-errors file after executing those commands.
Comment 8 Matthias Fuchs 2011-09-21 08:31:54 UTC
Created attachment 63811 [details]
xsession-errors file

Running these commands did add nothing to the xsesserion-errors file here.

In any case I attached it. What I did was:
1. Starting KDE with the cable plugged in
2. Unplugging cable
3. After some time running the commands you listed in #5
4. Plugging in the cable again.

Unfortunately the xesserion-errors file is also filled with stuff from Soprano etc. even though I deactivated all these in kdebugdialog, probably those are qDebug() etc. messages instead of the k version.
Comment 9 Lamarque V. Souza 2011-09-21 18:15:09 UTC
(In reply to comment #8)
> Created an attachment (id=63811) [details]
> xsession-errors file
> 
> Running these commands did add nothing to the xsesserion-errors file here.

They did add this line:

kded(3896)/networkstatus NetworkStatusModule::status:  status:  0
 
> In any case I attached it. What I did was:
> 1. Starting KDE with the cable plugged in
> 2. Unplugging cable
> 3. After some time running the commands you listed in #5
> 4. Plugging in the cable again.

You did more than that. You started your KDE session with NetworkManager stopped and start it after kded was already running. I think that is causing problems to kded's networkstatus module because the module tries to connect a signal to NM (QObject::connet) when it is created. However, that will not succeed because the QDBusInterface passed to QObject::connect will be invalid and kded's networkstatus module will not be able to track NM's status changes.

That explains why networkstatus returned status 0 (unknown), it should have returned status 1 (unconnected).

Probably that is not the cause of your inicial problem, but can you log with NetworkManager already running to see if the problem still happens?
 
> Unfortunately the xesserion-errors file is also filled with stuff from Soprano
> etc. even though I deactivated all these in kdebugdialog, probably those are
> qDebug() etc. messages instead of the k version.

That is not a problem for grep :-)
Comment 10 Matthias Fuchs 2011-09-23 10:16:51 UTC
So that means that I should make a clean restart -- with my cable connected -- and check what is added to the .xsession-errors file to see if networkmanager is started correctly here?

Btw. thanks for all your replies! :)
Comment 11 Lamarque V. Souza 2011-09-23 11:21:14 UTC
Almost, NM does not write to ~/.xsession-errors, Plasma NM, Solid's backend and networkstatus do. Since it seem there is nothing really wrong in NM's log I trying to figure out if there is something wrong in the KDE's part of the stack.

The 0 status reported is something wrong, but only that does not explain the Connected signal being emmited too early. I still do not see why it is emmiting that signal so early.
Comment 12 Matthias Fuchs 2011-09-23 17:58:09 UTC
What should I do to give you more information?
And how can I ensure that networkmanager is already running, the daemon should already be started before I reach kdm.
Comment 13 Lamarque V. Souza 2011-09-24 04:23:24 UTC
You should enable all debug using kdebugdialog and send me your .xsession-errors.
Comment 14 Matthias Fuchs 2011-09-26 20:53:49 UTC
Created attachment 63992 [details]
log

1. checking everything in kdebugdialog
2. removing ~/.xsession-errors
3. restarting with the cable connected
4. logging in
5. waiting a little then unplugging cable
6. after a while plugging in cable again
Comment 15 Lamarque V. Souza 2011-09-26 22:55:10 UTC
I think I know what is happening: you are using ntrack and ntrack is very optmistic to detect when your computer is online.

You can see that in your log, just search backwards (from the end of the log file) for the string "ntrack changed status:  1". That line triggers the statusChanged(Connected) signal. But look more ahead the line '"Wired connection 1" is activating' and the line 'NMWiredNetworkInterface::wiredPropertiesChanged: "State" QVariant(uint, 100)'.  The latter indicates the connection is activated and your computer is effectively online (according to NM).

Some lines before the line "ntrack changed status:  1" there is this line 'NMWiredNetworkInterface::wiredPropertiesChanged: "State" QVariant(uint, 20)', which indicates your wired card was detected by NM. 20 == Unavailable, that is, the card is working but there is no connection available yet. Even though there is no connection available ntrack signals that your computer is online.

Can you recompile kde-runtime without ntrack and see if that fixes your problem? I have never used ntrack, so I cannot help that much on how to disable it.
Comment 16 Lamarque V. Souza 2011-10-13 00:16:11 UTC
Have you tested using Solid::Networking::notifier() without ntrack?
Comment 17 Matthias Fuchs 2011-10-15 12:43:02 UTC
Sorry for not answering in a while.
I just tried without ntrack and then it works. :)

What special features are added by ntrack anyway?
Comment 18 Lamarque V. Souza 2011-10-15 16:07:06 UTC
I have never used ntrack, by what I have heard ntrack is a generic way to detect network state (disconnected, connecting, connected) independently of the network manager you use (NM, wicd, ifplugd, ifconfig, etc).

Unfortunately we have had some instability problems caused by ntrack before and now this problem. I will check if there is a way to use ntrack to really detect when the computer is connected to the Internet and not only connected to a network manager.
Comment 19 Lamarque V. Souza 2011-10-15 19:22:58 UTC
By the way, which ntrack version is installed in your computer?
Comment 20 Matthias Fuchs 2011-10-15 20:17:58 UTC
I am using ntrack 1:13
Comment 21 Lamarque V. Souza 2011-10-15 20:29:17 UTC
I am investigating ntrack's source code and it uses modules to do the tracking work. When there is no suitable module available it defaults to a noop module that always signals the computer is online. I think you do not have a suitable ntrack module for NM installed. Try running kded4 in the command line, if the message "no backend found: using built-in noop monitor (always online)." then you should check your ntrack installation.

Since you are using ntrack 0.13 maybe you are facing one of those bugs too:

https://bugs.launchpad.net/ntrack/+bug/750554
https://bugs.launchpad.net/ntrack/+bug/785119

By the way, which distribution do you use?
Comment 22 Lamarque V. Souza 2011-10-15 20:32:08 UTC
Anyway, this is an upstream bug so I will close it as such. You can still contact me through this bug entry if you have any more questions.
Comment 23 Matthias Fuchs 2011-10-15 23:25:17 UTC
I am using Arch Linux.

The message I get in xconfig-errors is "ntrack backend selected and created: ntrack-libnl1.so", in the console output I do _not_ have the message you noted.

So the issue is probably something else, but as you noted it has to do with ntrack.