Discussion:
sane_init()/sane_exit() crashes on debian systems / not on e.g. arch linux
(too old to reply)
Wilhelm
2017-04-05 14:55:39 UTC
Permalink
Raw Message
Hi all,

the following small program regularly crashes on debian based system
when inserting / removing a device. This does not happen on e.g. arch
linux or gentoo systems.

Investigating the problem further reveals that on debian based systems
every iteration starts a new thread ending up with tons of threads:
thats obviously the problem here.

On ArchLinux the sane_exit() call termintates the thread started in
sane_init() abd therefore no crash happens here.

Any reasons or plans to fix that?

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <sane/sane.h>

int main () {
while (true) {
SANE_Int sane_version = 0;
if (sane_init(&sane_version, 0) != SANE_STATUS_GOOD) {
printf("Can't init sane\n");
exit(EXIT_FAILURE);
}
printf("sane version %d.%d\n", SANE_VERSION_MAJOR(sane_version),
SANE_VERSION_MINOR(sane_version));

const SANE_Device** device_list = NULL;
if (sane_get_devices(&device_list, SANE_TRUE) == SANE_STATUS_GOOD) {
const SANE_Device** dev = device_list;
while (*dev) {
printf("dev name: %s\n", (*dev)->name);
dev++;
}
} else {
printf("Can't get dev list\n");
exit(EXIT_FAILURE);
}
sleep (1);
printf("sane_exit\n");
sane_exit();
sleep (1);
}
exit(EXIT_SUCCESS);
}
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Olaf Meeuwissen
2017-05-04 11:36:58 UTC
Permalink
Raw Message
Hi Wilhelm,
Post by Wilhelm
Hi all,
the following small program regularly crashes on debian based system
when inserting / removing a device. This does not happen on e.g. arch
linux or gentoo systems.
A bit late perhaps, but I've been trying to reproduce this without any
success.

I'm using Debian stretch (9.0 to be), last updated 2017-05-01 with a
default SANE configuration. I don't have scanbd installed and don't
have saned set up. I have an EPSON PM-A750 attached which is supported
by the epson2 backend.

I saved your program to debian-crash.c and compiled with:

gcc -lsane -o debian-crash debian-crash.c

Running ./debian-crash (I'm a member of the scanner group so no sudo is
required) did not produce the problem you describe. At least not in the
5 or 6 cycles I let it run for before killing it with Ctrl-C.
Post by Wilhelm
Investigating the problem further reveals that on debian based systems
thats obviously the problem here.
Hmm, tons of threads. There is nothing in the debian/patches/ (for
libsane-1.0.25-4) that changes the use of threads anywhere in the
sane-backends code. They only remove unneeded dependencies on
sanei/sanei_thread.lo and $(PTHREADS_LIB) for libsane.la (which is
really the dll backend).

So I think this is probably a backend specific issue. Since scanbd
requires the use of saned, my first suspect is the net backend but it
may be any other thread using backend as well.

The net backend does not use the sanei_thread API. It does use Avahi
thread APIs, if that's enabled (they are on Debian). Are those wrecking
the havoc you see? Could it be that libavahi changes triggered this?

Is any other backend responsible for this? If so, which one(s)?
Post by Wilhelm
On ArchLinux the sane_exit() call termintates the thread started in
sane_init() abd therefore no crash happens here.
I'm not familiar with the way Archlinux organizes its patches but tried
to find what you are talking about nevertheless. No such luck.

I found a network.patch that fixes something in sanei_tcp but without
any thread implications. There was a kodakaio avahi related patch as
well but that got included in sane-backends-1.0.25 and no longer seems
to get applied to Archlinux' sane-1.0.25-2.
Post by Wilhelm
Any reasons or plans to fix that?
Only if I know what backend is broken and in what way ;-)
BTW, a patch would be most helpful ;-)

Hope this helps,
--
Olaf Meeuwissen, LPIC-2 FSF Associate Member since 2004-01-27
GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13 F43E B8A4 A88A F84A 2DD9
Support Free Software https://my.fsf.org/donate
Join the Free Software Foundation https://my.fsf.org/join
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Olaf Meeuwissen
2017-05-06 05:58:44 UTC
Permalink
Raw Message
Hi again,
Post by Olaf Meeuwissen
Hi Wilhelm,
Post by Wilhelm
Hi all,
the following small program regularly crashes on debian based system
when inserting / removing a device. This does not happen on e.g. arch
linux or gentoo systems.
A bit late perhaps, but I've been trying to reproduce this without any
success.
I seem to be having more luck now.
Post by Olaf Meeuwissen
I'm using Debian stretch (9.0 to be), last updated 2017-05-01 with a
default SANE configuration. I don't have scanbd installed and don't
have saned set up. I have an EPSON PM-A750 attached which is supported
by the epson2 backend.
gcc -lsane -o debian-crash debian-crash.c
Running ./debian-crash (I'm a member of the scanner group so no sudo is
required) did not produce the problem you describe. At least not in the
5 or 6 cycles I let it run for before killing it with Ctrl-C.
After 10 cycles the pixma backend started printing warnings but no
crash. I had to enable localhost in the net backend to get things
to crash. That also happened at the 10th cycle (on my system).

sane version 1.0
[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open files[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open files[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open filesdebian-crash: thread-watch.c:171: avahi_threaded_poll_lock: Assertion `p' failed.
Aborted

I used f3f8afb0 with the debian/rules for 1.0.25-4 to configure and
build libraries. Running the same test with the libsane.so that
produces no longer triggered the above.
I let it run for 100 cycles but that did not trigger any crash.
Post by Olaf Meeuwissen
[snip]
Post by Wilhelm
Any reasons or plans to fix that?
Looks like it has been fixed in the latest code in git (although I don't
know what commit(s) were responsible for that). If you still see this
problem on your end with the latest version in git, please let us know
what is needed to reproduce and include more details on the symptoms you
see.

Hope this helps,
--
Olaf Meeuwissen, LPIC-2 FSF Associate Member since 2004-01-27
GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13 F43E B8A4 A88A F84A 2DD9
Support Free Software https://my.fsf.org/donate
Join the Free Software Foundation https://my.fsf.org/join
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Wilhelm Meier
2017-05-06 07:31:48 UTC
Permalink
Raw Message
Hi Olaf,
Post by Olaf Meeuwissen
Hi again,
Post by Olaf Meeuwissen
Hi Wilhelm,
Post by Wilhelm
Hi all,
the following small program regularly crashes on debian based system
when inserting / removing a device. This does not happen on e.g. arch
linux or gentoo systems.
A bit late perhaps, but I've been trying to reproduce this without any
success.
I seem to be having more luck now.
Post by Olaf Meeuwissen
I'm using Debian stretch (9.0 to be), last updated 2017-05-01 with a
default SANE configuration. I don't have scanbd installed and don't
have saned set up. I have an EPSON PM-A750 attached which is supported
by the epson2 backend.
gcc -lsane -o debian-crash debian-crash.c
Running ./debian-crash (I'm a member of the scanner group so no sudo is
required) did not produce the problem you describe. At least not in the
5 or 6 cycles I let it run for before killing it with Ctrl-C.
After 10 cycles the pixma backend started printing warnings but no
crash. I had to enable localhost in the net backend to get things
to crash. That also happened at the 10th cycle (on my system).
sane version 1.0
[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open files[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open files[bjnp] create_broadcast_socket: ERROR - can not open socket - Too many open filesdebian-crash: thread-watch.c:171: avahi_threaded_poll_lock: Assertion `p' failed.
Aborted
I used f3f8afb0 with the debian/rules for 1.0.25-4 to configure and
build libraries. Running the same test with the libsane.so that
produces no longer triggered the above.
I let it run for 100 cycles but that did not trigger any crash.
Post by Olaf Meeuwissen
[snip]
Post by Wilhelm
Any reasons or plans to fix that?
Looks like it has been fixed in the latest code in git (although I don't
know what commit(s) were responsible for that).
thank you for dealing with this issue.

This seems very reasonable to me since ArchLinux the package uses the
most recent sources whereas debian / ubuntu is a bit behind.

Well, I had to put a workaround into scanbd ...

Thanks again!
Post by Olaf Meeuwissen
If you still see this
problem on your end with the latest version in git, please let us know
what is needed to reproduce and include more details on the symptoms you
see.
Hope this helps,
--
Olaf Meeuwissen, LPIC-2 FSF Associate Member since 2004-01-27
GnuPG key: F84A2DD9/B3C0 2F47 EA19 64F4 9F13 F43E B8A4 A88A F84A 2DD9
Support Free Software https://my.fsf.org/donate
Join the Free Software Foundation https://my.fsf.org/join
--
sane-devel mailing list: sane-***@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
to sane-devel-***@lists.alioth.debian.org
Loading...