Skip to content

shell.trashItem crashes the process #28029

Closed

Description

@fabiospampinato

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    • 12.0.0
  • Operating System:
    • macOS 10.14
  • Last Known Working Electron version:
    • N/A

Expected Behavior

shell.trashItem should just work.

Actual Behavior

It does its job, and then immediately crashes the process.

To Reproduce

I don't have a fiddle, but this line makes the process crash for me:

return shell.trashItem ( path ).then ( () => true, () => false );

While this works:

return Promise.resolve ( shell.moveItemToTrash ( path, false ) );

In addition I'm getting as output from the main process:

{ reason: 'crashed', exitCode: 11 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
{ reason: 'crashed', exitCode: 5 }
and so on...

Basically it crashes the window with exit code 11, then my app opens gain the window after it crashed, and it crashes again immediately with exit code 5.

Activity

  1. ckerr commented on Mar 8, 2021

    @ckerr
    Member

    I think #28045 is an unrelated issue; but for triage purposes, its gist at
    https://gist.github.com/7fd1ca22aa15b089fc6573a0dd67841d does exercise shell.trashItem()

    This might be an macOS-specific issue. I'm not able to reproduce it when testing with Ubuntu 20.10 and Electron 12.0.0

  2. added
    has-repro-gist
    on Mar 8, 2021
  3. nornagon commented on Mar 12, 2021

    @nornagon
    Contributor

    I can't reproduce this with @ckerr's fiddle on macOS 10.15.7. trashItem completes successfully.

    Perhaps you could collect the crash report using crashReporter @fabiospampinato ? You can add this to your app, before the ready event:

    const { app, crashReporter } = require('electron')
    
    console.log(app.getPath('crashDumps'))
    crashReporter.start({
      submitURL: '',
      uploadToServer: false,
    })

    You should see the crash dump appear in the crash dumps directory. Zip it up and attach it here :)

  4. cata-code commented on Mar 13, 2021

    @cata-code

    I'm on Ubuntu 20.10, Electron 12.0.1

    After calling await shell.trashItem(file) in the preload.js file, the file gets moved to the trash folder and then Electron crashes. The call is being done in the renderer process by preloading a js file instead of using the less secure nodeIntegration

    For now I need to use the deprecated shell.moveItemToTrash(file) until this issue is fixed.

    I'm attaching the crash dump
    chromium-renderer-minidump-8d83213d6dfc95d6.zip

  5. nornagon commented on Mar 15, 2021

    @nornagon
    Contributor

    stack trace:

    Crash reason:  SIGSEGV /SEGV_MAPERR
    Crash address: 0x8
    Process uptime: not available
    
    Thread 14 (crashed)
     0  electron!content::BrowserTaskExecutor::GetUIThreadTaskRunner(content::BrowserTaskTraits const&) [scoped_refptr.h : 236 + 0x0]
        rax = 0x00007f7179f17170   rdx = 0x0000000000000004
        rcx = 0x0000000000000000   rbx = 0x00007f7179f17170
        rsi = 0x0000562594079fb8   rdi = 0x00007f7179f17170
        rbp = 0x00007f7179f170f0   rsp = 0x00007f7179f170f0
         r8 = 0x0000000000000000    r9 = 0x0ccccccccccccccc
        r10 = 0x0000000000000000   r11 = 0x0000000000000293
        r12 = 0x00007f7179f17187   r13 = 0x0000000000000000
        r14 = 0x00007f7179f17490   r15 = 0x00007f7179f17150
        rip = 0x0000562594f0f1c3
        Found by: given as instruction pointer in context
     1  electron!content::GetUIThreadTaskRunner(content::BrowserTaskTraits const&) [browser_thread_impl.cc : 89 + 0x5]
        rbx = 0x00007f7179f17170   rbp = 0x00007f7179f17110
        rsp = 0x00007f7179f17100   r12 = 0x00007f7179f17187
        r13 = 0x0000000000000000   r14 = 0x00007f7179f17490
        r15 = 0x00007f7179f17150   rip = 0x0000562594f0f18e
        Found by: call frame info
     2  electron!platform_util::TrashItemOnBlockingThread(base::FilePath const&, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>) [platform_util.cc : 22 + 0x13]
        rbx = 0x00007f7179f17170   rbp = 0x00007f7179f171b0
        rsp = 0x00007f7179f17120   r12 = 0x00007f7179f17187
        r13 = 0x0000000000000000   r14 = 0x00007f7179f17490
        r15 = 0x00007f7179f17150   rip = 0x0000562598fb1fb0
        Found by: call frame info
     3  electron!base::internal::Invoker<base::internal::BindState<void (*)(base::FilePath const&, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>), base::FilePath, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)> >, void ()>::RunOnce(base::internal::BindStateBase*) [bind_internal.h : 393 + 0x8]
        rbx = 0x00007f7179f171c0   rbp = 0x00007f7179f171d0
        rsp = 0x00007f7179f171c0   r12 = 0x0000000000000000
        r13 = 0x0000000000000000   r14 = 0x00007f7179f17490
        r15 = 0xaaaaaaaaaaaaaaaa   rip = 0x0000562598fb2179
        Found by: call frame info
     4  electron!base::TaskAnnotator::RunTask(char const*, base::PendingTask*) [callback.h : 101 + 0x3]
        rbx = 0x00007f7179f17248   rbp = 0x00007f7179f172b0
        rsp = 0x00007f7179f171e0   r12 = 0x0000000000000000
        r13 = 0x0000000000000000   r14 = 0x00007f7179f17490
        r15 = 0xaaaaaaaaaaaaaaaa   rip = 0x0000562594c1ef2e
        Found by: call frame info
     5  electron!base::internal::TaskTracker::RunContinueOnShutdown(base::internal::Task*) [task_tracker.cc : 646 + 0xc]
        rbx = 0x000056259af514b0   rbp = 0x00007f7179f172c0
        rsp = 0x00007f7179f172c0   r12 = 0x0000000000000000
        r13 = 0x00007f7179f17490   r14 = 0x00007f7179f17200
        r15 = 0x000056259b031a14   rip = 0x00005625971fbb47
        Found by: call frame info
     6  electron!base::internal::TaskTracker::RunTask(base::internal::Task, base::internal::TaskSource*, base::TaskTraits const&) [task_tracker.cc : 662 + 0x8]
        rbx = 0x000056259af514b0   rbp = 0x00007f7179f17470
        rsp = 0x00007f7179f172d0   r12 = 0x0000000000000000
        r13 = 0x00007f7179f17490   r14 = 0x00007f7179f17200
        r15 = 0x000056259b031a14   rip = 0x0000562594b6f9f2
        Found by: call frame info
     7  electron!base::internal::TaskTrackerPosix::RunTask(base::internal::Task, base::internal::TaskSource*, base::TaskTraits const&) [task_tracker_posix.cc : 22 + 0x11]
        rbx = 0x00007f7179f17490   rbp = 0x00007f7179f17530
        rsp = 0x00007f7179f17480   r12 = 0x00007f7179f17550
        r13 = 0x000029bde06f0d20   r14 = 0x00007f7179f17630
        r15 = 0x000029bde23679a0   rip = 0x0000562594b6f578
        Found by: call frame info
     8  electron!base::internal::TaskTracker::RunAndPopNextTask(base::internal::RegisteredTaskSource) [task_tracker.cc : 422 + 0x13]
        rbx = 0x00007f7179f17550   rbp = 0x00007f7179f176f0
        rsp = 0x00007f7179f17540   r12 = 0x00007f7179f17701
        r13 = 0x00007f7179f17700   r14 = 0x00007f7179f17748
        r15 = 0x000029bde06f0d20   rip = 0x0000562599a673e4
        Found by: call frame info
     9  electron!base::internal::WorkerThread::RunWorker() [worker_thread.cc : 349 + 0xe]
        rbx = 0x000029bde06f0d20   rbp = 0x00007f7179f177b0
        rsp = 0x00007f7179f17700   r12 = 0x00007f7179f17700
        r13 = 0x000029bde080b960   r14 = 0x00007f7179f17720
        r15 = 0x00007f7179f17748   rip = 0x000056259575fe41
        Found by: call frame info
    10  electron!base::internal::WorkerThread::RunPooledWorker() [worker_thread.cc : 223 + 0x5]
        rbx = 0x000029bde07f1f50   rbp = 0x00007f7179f177d0
        rsp = 0x00007f7179f177c0   r12 = 0x000029bde0752c80
        r13 = 0x000029bde080b960   r14 = 0x00007f7179f18640
        r15 = 0x00007f7179f18640   rip = 0x000056259575fbad
        Found by: call frame info
    11  electron!base::(anonymous namespace)::ThreadFunc(void*) [platform_thread_posix.cc : 87 + 0xa]
        rbx = 0x000029bde07f1f50   rbp = 0x00007f7179f17810
        rsp = 0x00007f7179f177e0   r12 = 0x000029bde0752c80
        r13 = 0x000029bde080b960   r14 = 0x00007f7179f18640
        r15 = 0x00007f7179f18640   rip = 0x0000562599a6d0f6
        Found by: call frame info
    12  libpthread.so.0!start_thread [pthread_create.c : 463 + 0x12]
        rbx = 0x0000000000000000   rbp = 0x0000000000000000
        rsp = 0x00007f7179f17820   r12 = 0x00007f71808141ce
        r13 = 0x00007f71808141cf   r14 = 0x0000000000000000
        r15 = 0x00007f7179f18640   rip = 0x00007f7185609590
        Found by: call frame info
    13  libc.so.6!__GI___clone + 0x43
        rbx = 0x00007f7179f18640   rbp = 0x0000000000000000
        rsp = 0x00007f7179f178c0   r12 = 0x00007f71808141ce
        r13 = 0x00007f71808141cf   r14 = 0x0000000000000000
        r15 = 0x00007f7179f18640   rip = 0x00007f7183d1b223
        Found by: call frame info
    
  6. cata-code commented on Mar 30, 2021

    @cata-code
  7. fabiospampinato commented on Apr 7, 2021

    @fabiospampinato
    ContributorAuthor

    Perhaps you could collect the crash report using crashReporter @fabiospampinato ? You can add this to your app, before the ready event:

    I can't actually because after upgrading to v12 now the crash reporter doesn't work anymore for me, the following is true for me: require('electron').crashReporter.start === undefined.

  8. nornagon commented on Apr 7, 2021

    @nornagon
    Contributor

    @fabiospampinato you'll need to put that code in the main process, not the renderer.

  9. fabiospampinato commented on Apr 10, 2021

    @fabiospampinato
    ContributorAuthor

    @nornagon Right, thanks. The changelog didn't mention that change and the docs still report the whole module as supported in the renderer process, like it was in v11 (or at least the app didn't crash when calling #start).

    Attached are the crash dump I've got after me trying to delete a file with the new API.

    crash_dumps.zip

  10. nornagon commented on Apr 20, 2021

    @nornagon
    Contributor

    There are a few apparently unrelated crashes in that zip, but this one has TrashItem in its stack:

    Crash reason:  EXC_BAD_ACCESS / KERN_INVALID_ADDRESS
    Crash address: 0x8
    Process uptime: 44 seconds
    
    Thread 5 (crashed)
     0  Electron Framework!content::BrowserTaskExecutor::GetUIThreadTaskRunner(content::BrowserTaskTraits const&) [scoped_refptr.h : 236 + 0x0]
        rax = 0x0000700002188890   rdx = 0x0000000000000004
        rcx = 0x0000000000000000   rbx = 0x0000700002188890
        rsi = 0x0000000107d72cb8   rdi = 0x0000700002188890
        rbp = 0x0000700002188810   rsp = 0x0000700002188810
         r8 = 0x0000000000000007    r9 = 0x00007ff4e09ad930
        r10 = 0x0000000000000008   r11 = 0x0000000000000008
        r12 = 0x00007000021888a7   r13 = 0x0000000108c76968
        r14 = 0x0000700002188bb8   r15 = 0x0000700002188870
        rip = 0x0000000101c75a43
        Found by: given as instruction pointer in context
     1  Electron Framework!content::GetUIThreadTaskRunner(content::BrowserTaskTraits const&) [browser_thread_impl.cc : 89 + 0x5]
        rbp = 0x0000700002188830   rsp = 0x0000700002188820
        rip = 0x0000000101adef0e
        Found by: previous frame's frame pointer
     2  Electron Framework!platform_util::TrashItemOnBlockingThread(base::FilePath const&, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>) [platform_util.cc : 22 + 0x13]
        rbp = 0x00007000021888d0   rsp = 0x0000700002188840
        rip = 0x0000000100de35a0
        Found by: previous frame's frame pointer
     3  Electron Framework!base::internal::Invoker<base::internal::BindState<void (*)(base::FilePath const&, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)>), base::FilePath, base::OnceCallback<void (bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)> >, void ()>::RunOnce(base::internal::BindStateBase*) [bind_internal.h : 393 + 0x8]
        rbp = 0x00007000021888f0   rsp = 0x00007000021888e0
        rip = 0x0000000100de3729
        Found by: previous frame's frame pointer
    [...]
    

    It looks like BrowserTaskExecutor::Get() is returning null. I think this can only happen early during startup. Are you calling trashItem before app.whenReady()?

  11. fabiospampinato commented on Apr 20, 2021

    @fabiospampinato
    ContributorAuthor

    There are a few apparently unrelated crashes in that zip, but this one has TrashItem in its stack:

    The app is configured to restart itself if it crashes, I guess it just keeps on crashing after that. I experience that kind of behavior many times actually when the app crashes for whatever reason.

    Are you calling trashItem before app.whenReady()?

    No. I'm calling it from the renderer process if it matters.

    Literally replacing this line of code:

    return Promise.resolve ( shell.moveItemToTrash ( path, false ) );

    With this one:

    return shell.trashItem ( path ).then ( () => true, () => false );

    Makes the app crash every single time that line of code is executed. No crashes with the sync version.

  12. nornagon commented on Apr 20, 2021

    @nornagon
    Contributor

    I'm calling it from the renderer process

    Oh! Of course, yes this would definitely matter. It looks like that code as written will only function in the main process. That's definitely a bug. Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    12-x-ybug 🪲has-repro-gistplatform/macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions