Opening a torrent executes a new instance of QBT

Bug #537718 reported by Patrick O'Callaghan
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
qBittorrent
Confirmed
Undecided
Christophe Dumez

Bug Description

Originally reported as bug 286968 and fixed at the time. This has now returned in 2.1.6 under KDE 4.4.

On downloading a .torrent file within my browser, a new instance of QBT is started even though there is one already running. The browser in this case is Google Chrome, but I doubt that matters.

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Unreproduceable here.

If you run qBittorrent from a term, is there any related error?

When qBittorrent is running, it should create a file:
/tmp/qBittorrent-uid (uid is often 1000)

Check that this file is properly created. And when the two qBittorrent instances are run at the same time, could you check if there are two files in /tmp. In that case, it would be possible that the two instances are run with a different uid.

Changed in qbittorrent:
assignee: nobody → Christophe Dumez (hydr0g3n)
status: New → Incomplete
Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote : Re: [Bug 537718] Re: Opening a torrent executes a new instance of QBT

Well, now I can't reproduce it :-) I rebooted my system after an update so
maybe there was something odd in my environment.

I'll check the /tmp file if it happens again and let you know.

Cheers

poc

On Fri, Mar 12, 2010 at 3:10 AM, Christophe Dumez <email address hidden> wrote:

> Unreproduceable here.
>
> If you run qBittorrent from a term, is there any related error?
>
> When qBittorrent is running, it should create a file:
> /tmp/qBittorrent-uid (uid is often 1000)
>
> Check that this file is properly created. And when the two qBittorrent
> instances are run at the same time, could you check if there are two
> files in /tmp. In that case, it would be possible that the two instances
> are run with a different uid.
>
> ** Changed in: qbittorrent
> Status: New => Incomplete
>
> ** Changed in: qbittorrent
> Assignee: (unassigned) => Christophe Dumez (hydr0g3n)
>
> --
> Opening a torrent executes a new instance of QBT
> https://bugs.launchpad.net/bugs/537718
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in qBittorrent - An advanced bittorrent client in C++ / Qt4:
> Incomplete
>
> Bug description:
> Originally reported as bug 286968 and fixed at the time. This has now
> returned in 2.1.6 under KDE 4.4.
>
> On downloading a .torrent file within my browser, a new instance of QBT is
> started even though there is one already running. The browser in this case
> is Google Chrome, but I doubt that matters.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/qbittorrent/+bug/537718/+subscribe
>

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

I am closing this bug for now since it was probably due to a system update (you are the only one reporting this). Feel free to reopen the bug if you experience it again.

Changed in qbittorrent:
status: Incomplete → Invalid
Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Sure, sorry for the noise.

poc

On Fri, Mar 12, 2010 at 10:22 AM, Christophe Dumez <email address hidden> wrote:

> I am closing this bug for now since it was probably due to a system
> update (you are the only one reporting this). Feel free to reopen the
> bug if you experience it again.
>
> ** Changed in: qbittorrent
> Status: Incomplete => Invalid
>
> --
> Opening a torrent executes a new instance of QBT
> https://bugs.launchpad.net/bugs/537718
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in qBittorrent - An advanced bittorrent client in C++ / Qt4: Invalid
>
> Bug description:
> Originally reported as bug 286968 and fixed at the time. This has now
> returned in 2.1.6 under KDE 4.4.
>
> On downloading a .torrent file within my browser, a new instance of QBT is
> started even though there is one already running. The browser in this case
> is Google Chrome, but I doubt that matters.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/qbittorrent/+bug/537718/+subscribe
>

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

No worries. I always prefer when the problem solves itself on its own :P

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

BTW, not relevant to this particular bug, but I recently noticed a
regression which means that QBT sometimes (in fact nearly always) doesn't
automatically pick up new torrent files from the download directory. I
thought I'd reported this but I don't see it on the Launchpad site. I'll
report it again if you like.

poc

On Fri, Mar 12, 2010 at 12:16 PM, Christophe Dumez <email address hidden> wrote:

> No worries. I always prefer when the problem solves itself on its own :P
>
> --
> Opening a torrent executes a new instance of QBT
> https://bugs.launchpad.net/bugs/537718
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in qBittorrent - An advanced bittorrent client in C++ / Qt4: Invalid
>
> Bug description:
> Originally reported as bug 286968 and fixed at the time. This has now
> returned in 2.1.6 under KDE 4.4.
>
> On downloading a .torrent file within my browser, a new instance of QBT is
> started even though there is one already running. The browser in this case
> is Google Chrome, but I doubt that matters.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/qbittorrent/+bug/537718/+subscribe
>

Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Is that also with v2.1.6? I know there have been an issue on this area with qBittorrent v2.2.0rc1 (which was fixed in rc2). I am not aware of any issue with v2.1.6. qBittorrent strongly relies on the system and particularly the kernel to detect FS changes (inotify).

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Yes, this is with 2.1.6. I just double-checked by copying a torrent file to
the directory, and QBT did nothing.

poc

On Fri, Mar 12, 2010 at 12:44 PM, Christophe Dumez <email address hidden> wrote:

> Is that also with v2.1.6? I know there have been an issue on this area
> with qBittorrent v2.2.0rc1 (which was fixed in rc2). I am not aware of
> any issue with v2.1.6. qBittorrent strongly relies on the system and
> particularly the kernel to detect FS changes (inotify).
>
> --
> Opening a torrent executes a new instance of QBT
> https://bugs.launchpad.net/bugs/537718
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in qBittorrent - An advanced bittorrent client in C++ / Qt4: Invalid
>
> Bug description:
> Originally reported as bug 286968 and fixed at the time. This has now
> returned in 2.1.6 under KDE 4.4.
>
> On downloading a .torrent file within my browser, a new instance of QBT is
> started even though there is one already running. The browser in this case
> is Google Chrome, but I doubt that matters.
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/qbittorrent/+bug/537718/+subscribe
>

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Returning to the original bug: it's back. I tried executing a new instance of QBT from the Shell and now have two copies running. There is no /tmp/qBittorrent-uid file. The /tmp directory is mode drwxrwxrwt.

In fact this occurs every time I log in, because under KDE 4.4 I use the "save session" option, and also have QBT in the Autostart file. This causes two instances to execute every time, which is pain.

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Correction: I had misunderstood your message and was looking for /tmp/qBittorrent-uid literally!. With two instances running, there is a single /tmp/qBittorrent-uid file:

$ ls -l /tmp/qBittorrent*
srwxrwxr-x 1 poc poc 0 2010-05-18 10:00 /tmp/qBittorrent-500

As you can see, it's empty. When I kill the second instance, the file vanishes even though there is an instance running. My UID is 500.

However, if I try a *third* instance (with two already running), the I get the message "Another qBittorrent instance is already running...".

So it looks like the problem is with the first instance either not creating the file, or the file being deleted as part of the startup process in KDE after QBT is already running.

Revision history for this message
SDERAWI (sderawi-deactivatedaccount) wrote :

+1 same issue here too [2.2.7]

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

I did some experimenting. If I turn off QBT in the KDE Autostart file, I get a single instance on login (because of the "save session" feature) and the /tmp/qBittorrent-uid exists. This implies that the problem is either with Autostart or with the order KDE executes various tasks while starting up. I'm going to post this to the Fedora KDE list in case anyone has seen it before.

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

I reported to the Fedora KDE list and got a reply from Rex Dieter (see http://lists.fedoraproject.org/pipermail/kde/2010-May/007082.html) suggesting a race condition in QBT.

I did the following experiment to confirm this:
1) Kill qbittorrent
2) Execute two simultaneous instances.

This is the result:

$ pgrep -fl qbittorrent
qbittorrent & qbittorrent &
[1] 15265
[2] 15266
$ Peer ID: -qB2260-
HTTP user agent is qBittorrent v2.2.6
Peer ID: -qB2260-
HTTP user agent is qBittorrent v2.2.6
Warning: Local domain socket was not closed cleanly, deleting file...

$ pgrep -fl qbittorrent
15265 qbittorrent
15266 qbittorrent

In other words, there *is* a race condition.

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Confirmed for 2.2.7 as well.

Changed in qbittorrent:
status: Invalid → Confirmed
Revision history for this message
Christophe Dumez (hydr0g3n) wrote :

Yes, there is a race condition. However, I'm not quite sure how to fix it.

I'm using sockets to detect if there is another instance running. As a consequence, if both instances are started at the same time, it won't necessarily detect each other because the sockets are not initialized yet.

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

I'm not familiar enough with the Qt class library, but I think you need to use a lock file as well as the socket, e.g. something like:

while ((fd = creat(lockfile, O_EXCL)) <= 0) {
  wait a few seconds
}
check the socket exists and use it
unlink (fd)

You can't use the socket itself for locking because it needs to accessed by two processes (reader and writer).

Revision history for this message
Patrick O'Callaghan (pocallaghan) wrote :

Oops, that should be

unlink (lockfile)

of course :-)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.