electron: [Bug]: `window.print()` without printers causes the main process to crash

Preflight Checklist

Electron Version

14.0.1

What operating system are you using?

Ubuntu

Operating System Version

5.11.0-37-generic #41-Ubuntu SMP Mon Sep 20 16:39:20 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

What arch are you using?

x64

Last Known Working Electron version

13.4.0

Expected Behavior

Calling window.print() should open the print window, even if there are no printers installed in the system.

Actual Behavior

Calling window.print() from the renderer process crashes the main process.

Testcase Gist URL

https://gist.github.com/85a5466567215173419a17982e79becb

Additional Information

When the process crashes, the terminal prints:

#0 0x5616b9f1e143 <unknown>
#1 0x5616b9fc517c <unknown>
#2 0x5616b9fc5141 close
#3 0x7f4c4568817b <unknown>

Failed to get crash dump id.
Report Id: --2021-09-27 12:

Failed to get crash dump id.
Report Id: --2021-09-27 12:
PATH/TO/PROJECT/node_modules/electron/dist/electron exited with signal SIGILL

When calling BrowserWindow.print(), the console prints: [22590:0927/121740.971531:ERROR:print_backend_cups.cc(218)] CUPS: Error getting default printer: No destinations added. and the print callback is called with [ false, 'no valid printers available' ] for args. The main process does not crash, but the print window never opens (I have filed a similar issue back at v10.x: https://github.com/electron/electron/issues/25498)

On v13.4.0, a similar error message is printed, but the process does not crashes (or does, but recovers immediately somehow):

Crashing due to FD ownership violation:
#0 0x564e03bc1143
<unknown>
#1 0x564e03c6817c <unknown>
#2 0x564e03c68141 close
#3 0x7f20e79ea17b <unknown>

Electron exited with signal SIGTRAP.
Saving files to temp directory...
Saved files to /tmp/tmp-18241-0f2HhywGTnpu
Electron v13.4.0 started.

Also, the print window is correctly displayed, containing only the ‘Print to File’ option.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 6
  • Comments: 28 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Hey,

The Crashing due to FD ownership violation: error is still an issue on all Electron 14+ releases. It’s caused by a safety measure added in Chromium 92. Doesn’t only happen in window.print() but also any native-module that calls fork() to summon a new child process. More details can be found here: https://bugs.chromium.org/p/chromium/issues/detail?id=1280227

I’ve tried to get in contact with anyone who could give some guidance on how we could get it fixed over the last few days (or at least what would be the best way to get it sorted), but didn’t get a single response.

If nobody from the electron team answers in the next 24 hours, I’ll check tomorrow how I can add an option on linux to turn off that FD ownership safety (since adding something to reset FD states after fork() seems like a lot of pain).

Have a nice day and I hope it helps!

This issue still exists. I was trying to print on my Ubuntu 22.04.2 LTS and have no printers attached to my pc. I get the error [20623:0625/195233.252880:ERROR:print_backend_cups.cc(220)] CUPS: Error getting default printer: No destinations added.

The app should atleast open a print window irrespective of whether there’s a printer or not.

@nornagon Here is a fresh crash dump. 😃 print-crash.zip

Same problem with v14 on Linux. It crashes the application: https://github.com/laurent22/joplin/issues/5651