Skip to content

fatal error: runtime.newosproc #7064

Closed
Closed

Description

@tomasz1986

The panic happened without any user intervention. Syncthing had just been doing its job, and I only found the log file later.

The log comes from Syncthing v1.10.0 (x86-32) running in Windows 10 Enterprise 2016 LTSB x86.

Panic at 2020-10-28T21:25:20+09:00
fatal error: runtime.newosproc

runtime stack:
runtime.throw(0x120fa12, 0x11)
	runtime/panic.go:1116 +0x64
runtime.newosproc(0x17ecafc0)
	runtime/os_windows.go:794 +0x146
runtime.newm1(0x17ecafc0)
	runtime/proc.go:1829 +0xbd
runtime.newm(0x13e5b7c, 0x12c2c000, 0x4a7, 0x0)
	runtime/proc.go:1808 +0x81
runtime.startm(0x12c2c000, 0x1)
	runtime/proc.go:1965 +0xac
runtime.handoffp(0x12c2c000)
	runtime/proc.go:2004 +0x28c
runtime.retake(0x68d8ec28, 0x4587, 0x0)
	runtime/proc.go:4805 +0x171
runtime.sysmon()
	runtime/proc.go:4713 +0x275
runtime.mstart1()
	runtime/proc.go:1172 +0x9b
runtime.mstart()
	runtime/proc.go:1137 +0x51

panic-20201028-212520.log

Activity

  1. added
    bug
    needs-triage
    on Oct 28, 2020
  2. AudriusButkevicius commented on Oct 28, 2020

    @AudriusButkevicius
    Member

    This is the OS refusing to start a thread when go asked for it.

    None of the code is ours and if anything would be a go runtime bug, but more likely issues with the os running out of handles or something.

  3. tomasz1986 commented on Oct 28, 2020

    @tomasz1986
    MemberAuthor

    It seems that the reason may be https://devblogs.microsoft.com/oldnewthing/?p=34773.

    Often I see people asking why they can’t create more than around 2000 threads in a process. The reason is not that there is any particular limit inherent in Windows. Rather, the programmer failed to take into account the amount of address space each thread uses.

    A thread consists of some memory in kernel mode (kernel stacks and object management), some memory in user mode (the thread environment block, thread-local storage, that sort of thing), plus its stack. (Or stacks if you’re on an Itanium system.)

    Usually, the limiting factor is the stack size.

    This program will typically print a value around 2000 for the number of threads.

    Why does it give up at around 2000?

    Because the default stack size assigned by the linker is 1MB, and 2000 stacks times 1MB per stack equals around 2GB, which is how much address space is available to user-mode programs.

    You can try to squeeze more threads into your process by reducing your stack size, which can be done either by tweaking linker options or manually overriding the stack size passed to the CreateThread functions as described in MSDN.

    The post comes from 2005 and seems to relate to a 32-bit installation of Windows only. My installation is 32-bit too, and I have also found

    runtime: failed to create new OS thread (have 1192 already; errno=8)
    

    in the "normal" Syncthing log, which would confirm the theory of 2000 threads limitation.

    The post mentions making tweaks in the code to "squeak in" more threads. Is this something that could be done in Syncthing, or would rather need to be done in the Golang itself?

  4. AudriusButkevicius commented on Oct 28, 2020

    @AudriusButkevicius
    Member

    There is not really a concept of a thread in Go, it's all managed by the runtime.

  5. calmh commented on Oct 29, 2020

    @calmh
    Member

    Likely the issue is with concurrent I/O, as that has a tendency of spawning more runtime threads. Using the various rate limiters to limit concurrent I/O requests might help.

  6. tomasz1986 commented on Oct 30, 2020

    @tomasz1986
    MemberAuthor

    Likely the issue is with concurrent I/O, as that has a tendency of spawning more runtime threads. Using the various rate limiters to limit concurrent I/O requests might help.

    Is this something that needs to be done at the OS level? I do not believe that Windows has this kind of control though. I guess that limiting the folder concurrency in Syncthing could help here, but I prefer to keep it at -1 for other reasons. As long as this was a one-time occurrence, I will probably just ignore it.

    I have received no feedback on the Go forums anyway.

  7. calmh commented on Oct 30, 2020

    @calmh
    Member

    I don't know your setup but my guess would be lots of connected devices doing lots of concurrent requests, which we have controls for (max concurrent incoming request data). Folder concurrency might add to it, but I think that should be minor unless you have more than a thousand folders.

  8. tomasz1986 commented on Oct 30, 2020

    @tomasz1986
    MemberAuthor

    Hmm, that is strange then, because I have only 4 devices connected. There are 29 folders though, hence the question about folder concurrency.

    This is how the device in question looks like. Not a minimal configuration, but also nothing extreme, at least in my eyes.

    image

  9. calmh commented on Oct 30, 2020

    @calmh
    Member

    Then I have no good explanation

  10. calmh commented on Oct 30, 2020

    @calmh
    Member

    Or, well, I do. The panic log shows a large amount of outstanding requests, many blocked on disk I/O. So reducing the max request kib (per folder) and/or folder concurrency should help.

  11. imsodin commented on Oct 30, 2020

    @imsodin
    Member

    Specifically the MaxConcurrentWrites folder option is 2 by default, while in the panic there are 1184 ongoing write operations on the same folder. Setting that to unlimited is madness. Please always specify any changed configuration when reporting.

  12. tomasz1986 commented on Oct 30, 2020

    @tomasz1986
    MemberAuthor

    @calmh

    Or, well, I do. The panic log shows a large amount of outstanding requests, many blocked on disk I/O. So reducing the max request kib (per folder) and/or folder concurrency should help.

    This is a good clue, because while the device does use only flash storage, it is rather slow. I have the folders spread on two different disks.

    1. Built-in eMMC (not great, but passable)
    > Disk  Random 16.0 Read                       30.31 MB/s
    > Disk  Sequential 64.0 Read                   110.89 MB/s
    > Disk  Sequential 64.0 Write                  32.17 MB/s
    > Average Read Time with Sequential Writes     0.916 ms
    > Latency: 95th Percentile                     2.207 ms
    > Latency: Maximum                             42.122 ms
    > Average Read Time with Random Writes         1.118 ms
    
    1. SD Card (very slow)
    > Disk  Random 16.0 Read                       8.31 MB/s
    > Disk  Sequential 64.0 Read                   19.01 MB/s
    > Disk  Sequential 64.0 Write                  7.67 MB/s
    > Average Read Time with Sequential Writes     3.272 ms
    > Latency: 95th Percentile                     8.560 ms
    > Latency: Maximum                             435.594 ms
    > Average Read Time with Random Writes         7.405 ms
    

    Do you mean tweaking PullerMaxPendingKiB? What value should I change it to though? There is nothing in the Docs explaining it, but I am guessing that it is set using the following code.

    defaultPullerPendingKiB = 2 * protocol.MaxBlockSize / 1024
    if f.PullerMaxPendingKiB == 0 {
    f.PullerMaxPendingKiB = defaultPullerPendingKiB
    }

    Is there any way to know what value is currently being used for PullerMaxPendingKiB?

    @imsodin

    Specifically the MaxConcurrentWrites folder option is 2 by default, while in the panic there are 1184 ongoing write operations on the same folder. Setting that to unlimited is madness. Please always specify any changed configuration when reporting.

    The de facto default value for MaxConcurrentWrites is actually 0 (see #7033). I have not really changed any defaults on this particular device, except for setting maxFolderConcurrency to -1, which I always do (the reason explained in https://forum.syncthing.net/t/concurrency/14607).

    Should I manually change MaxConcurrentWrites from 0 (set by Syncthing) to 2?

  13. imsodin commented on Oct 30, 2020

    @imsodin
    Member

    The de facto default value for MaxConcurrentWrites is actually 0 (see #7033). I have not really changed any defaults on this particular device, except for setting maxFolderConcurrency to -1, which I always do (the reason explained in https://forum.syncthing.net/t/concurrency/14607).

    That's indeed bad. For this particular problem the following proposed change will mitigate it, however we should really fix the folder defaults issue in general.
    #7069

    Should I manually change MaxConcurrentWrites from 0 (set by Syncthing) to 2?

    Yes

  14. added
    frozen-due-to-age
    on Oct 29, 2021
  15. locked and limited conversation to collaborators on Oct 29, 2021
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

    bugfrozen-due-to-ageneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions