Syncthing loses its contact with the browser

I use to have Syncthing running in two computers. Everything works fine. I usually start the computers and Syncthing in the morning and have it running until I switch of the computers in the evening. Both computers run Syncthing v0.11.26 (64 bit) in Windows 7. Syncthing is started automatically upon login and runs without opening a browser. I start a browser (SeaMonkey, Firefox) manually (http://127.0.0.1:8080/) presenting Syncthing status and have it running. In the evening, when I select Actions and Shutdown, nothing happens. If I refresh the browser window and then select Actions and Shutdown, Syncthing shuts down, which it confirms. (Sometimes Syncthing shuts down without confirming the shutdown. If I then refresh the browser window, there is no Syncthing.) Somehow the contact between the browser and Syncting ceases after a couple of hours. The contact between the browser and URLs other than Syncthing’s isn’t lost.

This is not important, since Syncthing works fine, but is there a maximum time for the contact between Syncthing and a brower?

Not that I know of, but I’ve never tested this either. There’s a session cookie, which supposedly should not expire while the session (browser instance) is alive. Things to check when this happens:

  • Does status update, before you issue commands like restart? CPU utilization for example, should fluctuate a little every 10-15 seconds or so.

  • If not, are there errors in the Javascript console in the browser?

  • Does a browser reload before doing anything else bring things back to life?

Tonight, after having Syncthing and the browser running all day in two computers, the browser in both computers reported different CPU utilization every 10-15 seconds. The Javascript error console had no messages related to Syncthing. In one of the computers I refreshed the window before selecting Actions and Shutdown. Syncthing confirmed the shutdown.

In the other computer the browser reported Scanning now and then, and varying CPU utilization, that is, both the browser and Syncthing were running and had a connection, at least in one direction. I selected Actions and Shutdown. Nothing changed. The browser continued reporting varying CPU utilization and Scanning. I selected Actions and Shutdown once more. Nothing changed. The browser continued reporting varying CPU utilization and Scanning. Then I refreshed the browser window and selected Actions and Shutdown. Syncthing confirmed the shutdown promptly.

So apparently after running the same instance of Syncthing and the browser for hours, a browser refresh is needed to enable Shutdown from the browser.

So shutdown and other things that affect syncthing (config pushes, rescan commands, etc) are POST requests and require either a CSRF token or an API key to be accepted. Getting the CPU utilization and other status are GET requests where we are more lenient towards.

Do you have authentication configured? If not, it seems we are somehow expiring or forgetting the CSRF token. If you do, it could be something more complex, possibly.

possibly related: sometimes the “rescan (all)” buttons don’t work. I managed to open Firebug and it showed a 403 POST error “CSRF Error”. It doesn’t happen every time I open the GUI and sadly I cannot reliably reproduce it (except delete the cookie and hit rescan). No authentication is set, the only (maybe?) important setting in Firefox is “delete all cookies on exit”.

I use default settings in Syncthing, Firefox, and SeaMonkey. There is nothing about authentication in Syncthing’s config.xml. I find nothing like “delete all cookies on exit” in my browser configurations.

Sounds like the CSRF stuff is failing somewhere, after a while, then.

Observation with non-Mozilla browsers:

Today I had Syncthing running and Chrome watching it. After more than 14 hours the web interface was still alive. Then I selected Actions and Shutdown. Syncthing shut down promptly and confirmed.

In another computer I ran Syncthing and Internet Explorer watching it. After more than 14 hours the web interface was still alive. Then I selected Actions and Shutdown. Syncthing shut down promptly and confirmed.

This is just one try, but it might indicate a problem in the cooperation between Syncthing and Mozilla browsers (Firefox, SeaMonkey), possibly depending of some setting.

More observations:

After running Syncthing and Chrome or Syncthing and Opera for hours, I was unable to shut down Syncthing from the browser. The browser interface was alive (a.o. the CPU usage changed), but Shutdown had no effect. I tried Restart. Syncthing said that it restarted, but it didn’t, as the Uptime wasn’t reset and the log file hadn’t been updated. After the “restart”, Shutdown still had no effect. After reloading the browser window, Shutdown worked. There was a CSRF cookie until the browser was closed.

So the Shutdown problem pertains not only to Mozilla browsers. I have seen the problem several times with different browsers.

I think you should get the CSRF value, and see if its a value that is available in the CSRF text file which is in syncthings home dir. Also check the value after refreshing the page.

Observation of Syncting cookies.

Scenario: Syncthing running 15h 8m, Firefox watching it, browser window “alive”.

Cookies according to Firefox:

CSRF-Token-HWL2C=d0ztd-jUMbvO5eeFejWtOmPNRt0fOAxU

Host: 127.0.0.1

Path: /vendor/font-awesome/fonts/

Expires: When the browser closes (session)

Attributes: None

hvX6Ro-rerk55YdhnWmmzvHduIETHI

Host: 127.0.0.1

Path: /qr/

Expires: When the browser closes (session)

Attributes: None

csrftokens.txt:

MucHUgAh3i-5OO5x0Q7KehSLO2HaLB6v

WSiHn5qJ6YzoIJV3N5usZe6wO1dBHryF

A4NWXId8rCjXBAHYZv0bobc7kuGt9NWR

rVVeKh-vktMhBrMJRnFSpvWB2NGLf59g

nYiuuA7vB1hIdSb5apHxcHYr31Qtj7eW

wuXu960kfFafwes36SkPOMgr0onygcqt

60oA6kYWfUSYjAajPoqShak8SLo5z0Wt

bI2I9-7uv0-WSXwR8iT0EjdeIxT2J9mA

d0ztd-jUMbvO5eeFejWtOmPNRt0fOAxU

PehvX6Ro-rerk55YdhnWmmzvHduIETHI

Actions -> Shutdown: No effect (Repeatable)

Actions -> Restart: Popup “Syncthing is restarting. Please wait…”, Otherwise no effect on browser window, cookies or csrftokens.txt.

I reloaded the browser window. The browser’s cookie list changed to:

CSRF-Token-HWL2C=d0ztd-jUMbvO5eeFejWtOmPNRt0fOAxU

Host: 127.0.0.1

Path: /vendor/font-awesome/fonts/

Expires: When the browser closes (session)

Attributes: None

CSRF-Token-HWL2C=PehvX6Ro-rerk55YdhnWmmzvHduIETHI

Host: 127.0.0.1

Path: /qr/

Expires: When the browser closes (session)

Attributes: None

CSRF-Token-HWL2C=Ytw0tjd0ZxGsXtT4D2La3E5gwntm0E8L

Host: 127.0.0.1

Path: /

Expires: When the browser closes (session)

Attributes: None

csrftokens.txt changed to:

WSiHn5qJ6YzoIJV3N5usZe6wO1dBHryF

A4NWXId8rCjXBAHYZv0bobc7kuGt9NWR

rVVeKh-vktMhBrMJRnFSpvWB2NGLf59g

nYiuuA7vB1hIdSb5apHxcHYr31Qtj7eW

wuXu960kfFafwes36SkPOMgr0onygcqt

60oA6kYWfUSYjAajPoqShak8SLo5z0Wt

bI2I9-7uv0-WSXwR8iT0EjdeIxT2J9mA

d0ztd-jUMbvO5eeFejWtOmPNRt0fOAxU

PehvX6Ro-rerk55YdhnWmmzvHduIETHI

Ytw0tjd0ZxGsXtT4D2La3E5gwntm0E8L

Actions -> Shutdown: Syncthing shut down.

The same behaviour was observed in a different computer with Syncthing and the Chrome browser.

Without being familiar with the internals of Syncthing, I guess that Syncthing forgets its cookies after running for a couple of hours and needs a fresh cookie to react properly.

After running for 3 hours and a few minutes, another instance of Syncthing (in another computer) didn’t react to the Shutdown command, seemingly having forgotten its cookie. Refreshing the browser window solved the problem.

Something may be reloading, requesting new CSRF tokens, causing the one the browser has to be rotated away…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.