Skip to content

ALSA function 'snd_pcm_open' failed with error 'EHOSTDOWN: Host is down' #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
koutheir opened this issue May 28, 2023 · 29 comments · Fixed by #259
Closed

ALSA function 'snd_pcm_open' failed with error 'EHOSTDOWN: Host is down' #224

koutheir opened this issue May 28, 2023 · 29 comments · Fixed by #259
Labels
bug Something isn't working Linux Something related to Linux operating system
Milestone

Comments

@koutheir
Copy link

The application crashes when I try to raise the notification volume:

thread 'thread_play_sound' panicked at 'called `Result::unwrap()` on an `Err` value:
DefaultStreamConfigError(BackendSpecific { err: BackendSpecificError { 
    description: "ALSA function 'snd_pcm_open' failed with error 'EHOSTDOWN: Host is down'" 
} })',
src/notifications/types/sound.rs:61:72

To Reproduce

  1. Open the application.
  2. Enter the password for sudo.
  3. Click on the settings button.
  4. Slide the notification volume to the right (for a higher volume).
  5. The application crashes.

Expected behavior

The application should continue running.

Crash log
Here it is: crash.log

Environment

  • Version: 1.2.0
  • OS: Debian Linux 12. Linux 6.1.0.
@koutheir
Copy link
Author

If it helps:

  • libasound2 version 1.2.8
  • pipewire version 0.3.65
  • pulseaudio is not installed
  • KDE version 5.27.2

@GyulyVGC
Copy link
Owner

It crashes at this line.
It seems it cannot find the default output device for audio.
I can suggest you to verify that libasound2-dev is installed and updated to the latest version.

@GyulyVGC GyulyVGC added the bug Something isn't working label May 28, 2023
@koutheir
Copy link
Author

❯ apt show libasound2-dev
Package: libasound2-dev
Version: 1.2.8-1+b1
Priority: optional
Section: libdevel
Source: alsa-lib (1.2.8-1)
Maintainer: Debian ALSA Maintainers <[email protected]>
Installed-Size: 677 kB
Provides: libasound-dev
Depends: libasound2 (= 1.2.8-1+b1)
Suggests: libasound2-doc
Homepage: https://www.alsa-project.org/
Tag: devel::library, role::devel-lib, works-with::audio
Download-Size: 110 kB
APT-Manual-Installed: yes
APT-Sources: https://deb.debian.org/debian testing/main amd64 Packages
...

@GyulyVGC
Copy link
Owner

I forgot to mention that I built the DEB package on ubuntu-latest, which has already caused some problems of compatibility with Debian in the past.
Did you install Sniffnet from the DEB package?

@koutheir
Copy link
Author

Screenshot_20230528_121522

@koutheir
Copy link
Author

Did you install Sniffnet from the DEB package?

Yes.

@koutheir
Copy link
Author

❯ sha256sum Sniffnet_Linux.deb
8c7b93d35f00fea47077688e7642f4c8dac2826e294aa503c500fb7a4b19d369  Sniffnet_Linux.deb

@GyulyVGC
Copy link
Owner

Did you install Sniffnet from the DEB package?

Yes.

I suspect that could be the problem then.
If you have Rust installed, you could try directly building from source with cargo.

@koutheir
Copy link
Author

If you have Rust installed, you could try directly building from source with cargo.

I have it installed. Would installing using cargo also set up menu items and the like?

@GyulyVGC
Copy link
Owner

Installing from cargo would just build and install the binary to be run from CLI.
Also, you would have to ensure to delete the previous version coming from the DEB package which is in usr/bin to be sure to launch the cargo version when typing sudo sniffnet from terminal.

@GyulyVGC
Copy link
Owner

I don't know if building locally with cargo can solve the issue, but I think it's worth trying

@koutheir
Copy link
Author

I uninstalled the APT package, then run cargo install sniffnet. Then:

❯ which sniffnet
/home/koutheir/.cargo/bin/sniffnet

Running sniffnet from a terminal without sudo does not reproduce the issue.

Running it with sudo reproduces the issue, but now with a different error:

❯ sudo sniffnet
[sudo] password for koutheir: 
...
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dsnoop.c:540:(snd_pcm_dsnoop_open) The dsnoop plugin supports only capture stream
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:972:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
fish: Job 1, 'sudo sniffnet' terminated by signal SIGFPE (Floating point exception)

Is the problem that sudo removes a lot of environment variables that are required for ALSA to work?

@koutheir
Copy link
Author

Running the application with su instead of sudo fixes the issue, because the environment variables are kept.

@koutheir
Copy link
Author

Is there a way to avoid running the application as root?

@koutheir
Copy link
Author

This fixes the issue:

❯ sudo -E sniffnet

Can you please update the shortcuts in the .deb package to pass the -E option to sudo when running the application?

@koutheir
Copy link
Author

Ideally, the application should not run as root. If you need some root capabilities, then running a small daemon as root and communicating with that is far more secure.

@GyulyVGC
Copy link
Owner

This fixes the issue:

❯ sudo -E sniffnet

Can you please update the shortcuts in the .deb package to pass the -E option to sudo when running the application?

Thanks very much for having spotted the cause.
Of course I will update it before the next release.

You can also avoid running the app as sudo by giving Sniffnet privileges to inspect network adapter with:

sudo setcap cap_net_raw,cap_net_admin=eip <your/Sniffnet/executable/path>

@GyulyVGC GyulyVGC added the Linux Something related to Linux operating system label May 28, 2023
@koutheir
Copy link
Author

You can also avoid running the app as sudo by giving Sniffnet privileges to inspect network adapter with:

sudo setcap cap_net_raw,cap_net_admin=eip <your/Sniffnet/executable/path>

Why didn't the .deb package do that to the executable at installation time? Why does the desktop menu shortcut run it with sudo instead?

@GyulyVGC
Copy link
Owner

I didn't dig into a way to do that and I must admit that packages are still in a pretty basic form.

If you know how to do that and would like to help, you can edit the resources/sniffnet.desktop folder and submit a PR.

@koutheir
Copy link
Author

I never did that before, but I know it is possible because a Debian package can run a shell script as root during installation after files are copied in place. Once that is done, the .desktop file wouldn't need to run the application as root.

@koutheir
Copy link
Author

How do you generate the .deb packages?

@GyulyVGC
Copy link
Owner

With an automated GitHub workflow (.github/workflows/package.yml)

@GyulyVGC
Copy link
Owner

I never did that before, but I know it is possible because a Debian package can run a shell script as root during installation after files are copied in place.

I can try to better document myself then

@koutheir
Copy link
Author

I found out that you're using cargo deb to generate the .deb file. As far as I understand, cargo deb supports specifying a postinst script by setting the maintainer-scripts key inside [package.metadata.deb].

@4r7if3x
Copy link
Contributor

4r7if3x commented Jun 1, 2023

This issue has been addressed in my incoming PR. (#228 is also considered)

@GyulyVGC
Copy link
Owner

GyulyVGC commented Jun 1, 2023

This issue has been addressed in my incoming PR. (#228 is also considered)

Tyvm ❤️

@GyulyVGC GyulyVGC added this to the v1.2.1 milestone Jun 1, 2023
@GyulyVGC
Copy link
Owner

GyulyVGC commented Jun 7, 2023

Hey @koutheir

We changed the building strategy and we are looking for feedback/testers to see if we finally solved this issue.

Could you kindly try the new package available below?

Sniffnet_LinuxDEB_amd64.deb.zip

Thanks in advance.

@GyulyVGC GyulyVGC linked a pull request Jun 8, 2023 that will close this issue
@koutheir
Copy link
Author

koutheir commented Jun 8, 2023

Installing works and the issue is fixed.

Also:

$ getcap /usr/bin/sniffnet
/usr/bin/sniffnet cap_net_admin,cap_net_raw=eip
$ grep '^Exec=' /usr/share/applications/sniffnet.desktop
Exec=/usr/bin/sniffnet

So the executable capabilities are set correctly and sudo is not used.

@GyulyVGC
Copy link
Owner

GyulyVGC commented Jun 8, 2023

Amazing, thanks for the confirmation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Linux Something related to Linux operating system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants