Skip to content

Pausing/resuming folder using API changes folder rescan settings #10389

Closed

Description

@theraser

What happened?

It is possible to pause/resume folders using the API like this:
curl -k -X PATCH -H “X-API-Key: foobar” ``https://localhost:8384/rest/config/folders/“xxxxx-xxxxx”`` -d ‘{ “paused”: true }’"

This works as expected, however those requests changes some other folder settings silently. It resets the “rescanIntervalS” for my folders to 3600 - no matter what I configured earlier. And the “Watch for Changes” setting is also reset to "enabled". It even resets those values if a "paused: false" is send to a activated folder, it then just resets the rescan interval to 1h. I have no idea where those 3600 are coming from because my default folder setting is another value and I configured some other value for this folder before using the API. This problem exists for a longer time but I now finally found the time to debug this a bit more.

Steps to reproduce

Set the “Full Rescan Interval (s)” using the Webinterface for one folder to 7200 or any other value, save changes. Verify that changes are written to .config/syncthing/config.xml (that does work for me). Then run curl -k -X PATCH -H “X-API-Key: foobar” ``https://localhost:8384/rest/config/folders/“xxxxx-xxxxx”`` -d ‘{ “paused”: true }’"

Check again the Webinterface: The folder is paused as expected but “Full Rescan Interval (s)” will be 1h/3600s again.

Known workaround

Thanks to the forum I verified that those resets are not happening if I use a command like syncthing cli config folders xxxxx-xxxxx paused set true instead of using the API

Syncthing version

2.0.8

Platform & operating system

Arch Linux

Browser version

Firefox 142.0.1

Relevant log output

Activity

  1. added
    bug
    on Sep 12, 2025
  2. added theissue type on Sep 12, 2025
  3. added
    needs-triage
    on Sep 12, 2025
  4. prashant933 commented on Oct 1, 2025

    @prashant933

    Hi, I am new to syncthing and wanted to contribute to the project. Can I look into this issue? If yes, can you please assign this issue to me. Thanks

  5. tomasz1986 commented on Oct 1, 2025

    @tomasz1986
    Member

    We don't assign issues. If you want to contribute, please file a pull request. You may also want to read up https://github.com/syncthing/syncthing/blob/main/CONTRIBUTING.md#contributing-code before doing so.

  6. prashant933 commented on Oct 1, 2025

    @prashant933

    Sure. Will start working on it then. Thanks

  7. prashant933 commented on Oct 1, 2025

    @prashant933

    I found that the issue is related to the way we perform json.unmarshal(). folderconfiguration.go is having a function UnmarshalJSON(data []byte) which is called whenever we try to unmarshal, but the problem is we perform
    structutil.SetDefaults(f) on the very first line.
    This causes default values defined in the struct to be populated.

    An easy fix is to update SetDefaults() function to not populate any default value if the underlying struct already has some value corresponding to that field.
    But I wanted to take suggestions if this looks ok or not. I don't have full context as to what might go wrong if I added this piece of code into SetDefaults(). Otherwise we need to find a way to restore original values after we had performed SetDefaults

  8. AudriusButkevicius commented on Oct 3, 2025

    @AudriusButkevicius
    Member

    I don't think you can easily distinguish between "has no value" vs "has been explicitly set to not have a value, which is different from default".
    Perhaps you could unmarshal the json into an empty folder somehow, without setting defaults, and then walk the fields that are set and only set them.
    Or walk the json key by key and explicitly unmarshal values for those keys, into the struct fields.
    Not sure.

  9. nf-brentsaner commented on Dec 4, 2025

    @nf-brentsaner

    I don't think you can easily distinguish between "has no value" vs "has been explicitly set to not have a value, which is different from default".

    You can, actually - use pointers for struct fields and omitempty option on the json/xml struct tags. (It's not strictly necessary for JSON, as it has a native null representation that can be mapped to nil, but would be necessary for XML to prevent it from marshaling a zero-value on a nil field).
    nil ptr == "not present in original data" (e.g. XML from config or JSON from request), non-nil ptr pointing to the type's zero value == "explicitly set as zero value".

    I haven't taken a look at the struct defs, so this might be a significant refactoring if pointers aren't already being used. However, since you maintain your own defaults setter, this would allow you to check for an 'allowzero' option in the default tag that applies to ptr fields (ignored otherwise) that does not set a default on a nnon-nil-but-zero-value vs. nil field value (see reflect.Value.IsNil(), reflect.Value.IsValid(), reflect.Value.IsZero()) that dictates how your defaults setter handles nil fields.

  10. added a commit that references this issue on Jun 23, 2026
    e4d08b3
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

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions