Shadowsocks-windows: A logic for save current settings may need fix within Updates "record user wininet settings and restore after use"

Created on 21 May 2017  ·  14Comments  ·  Source: shadowsocks/shadowsocks-windows

Please read Wiki carefully, especially https://github.com/shadowsocks/shadowsocks-windows/wiki/Troubleshooting.
Please answer these questions before submitting your issue. Thanks!

Version(release version or AppVeyor link)

from v4.0

Environment(Operating system, .NET Framework, etc)

Windows 10 .Net4.6

Steps you have tried

many times for Toggle Enable System Proxy

What did you expect to see?

Save should record original user settings.

What did you see instead?

IE Proxy be changed as last SS Win using.

Config and error log in detail (with all sensitive info masked)

None.

bug

Most helpful comment

看了下,可能和 https://github.com/shadowsocks/shadowsocks-windows/blob/master/shadowsocks-csharp/Controller/ShadowsocksController.cs#L47 有关,因为之前只是单纯的要关闭或者是打开,现在因为会恢复用户的设置,所以,这个flag应该需要其他工作。

All 14 comments

After system proxy is turned off, we should re-record user settings.

If you have any idea on improving it, open PR

But.. with current code logic, the SS will not save user settings, it will always save SSWin settings after user toggle "Enable System Proxy" many times.
Maybe first time the code works fine, but after many time trigger "Enable System Proxy", it will lost user settings.

My build with attached code changes works correct with your mind!
We should always use the first time saved user data to restore current settings when exiting or disabling SS.
Thanks!

你的代码逻辑有问题

  1. 用户设置一
  2. 开启系统代理
  3. 关闭系统代理
  4. 用户设置二
  5. 开启系统代理
  6. 关闭系统代理
  7. 用户设置三

这种流程下,预计应该还原到『用户设置二』,但是你的逻辑会还原到『用户设置一』

remove my code. sorry, I was wrong!

the root cause is a Windows shut down and user logoff when SS is working.

if user current wininet setting is PROXY_TYPE_AUTO_DETECT .
|
SS start - enable && global, so wininet is PROXY_TYPE_PROXY , and save user's ROXY_TYPE_AUTO_DETECT
|
Windows shutdown or user logoff. (Wininet keeping PROXY_TYPE_PROXY , and lost saving user's)
|
Back to Windows and Start up SS again.
|
SS start -enable && global, the wininet is is PROXY_TYPE_PROXY, and save previous Wininet keeping PROXY_TYPE_PROXY as user record.
|
SS Exit or Disable, restore user's as PROXY_TYPE_PROXY .
|
Can't access service anymore.

I think a handling for OS shutdown or user logoff event for restore user wininet settings is needed for fix this problem.

看了下,可能和 https://github.com/shadowsocks/shadowsocks-windows/blob/master/shadowsocks-csharp/Controller/ShadowsocksController.cs#L47 有关,因为之前只是单纯的要关闭或者是打开,现在因为会恢复用户的设置,所以,这个flag应该需要其他工作。

That's right, and also need restore user's wininet setting when:

  1. user Quit Click.
  2. App exit.
  3. system shutdown or user logoff.

the first two steps already covered by current codes, but we lost user settings when force Windows shutdown or user logoff. so, a handling for OS shutdown or user logoff event may need for restore.

@wongsyrone
private bool _systemProxyIsDirty = false;
这个可能要需要在磁盘上做一下持久化,防止意外关闭后忘记原来的设置。

  1. 应用代理的时候写入备份到文件
    2a. 取消代理时还原备份,删除文件
    2b. 若之前有过非正常退出,启动ss的时候若检查到存在备份文件,则提示用户是否保留该备份或者使用新的内容覆盖?

然而目前的系统代里设置是sysproxy负责的

I tried to add a new event handle SessionEnding of SystemEvents in Main, it could catch the shutdown or user logoff successfully, but the MainController and sysproxy threads already be killed at this moment.

Fixed with write temporary "user_wininet,conf" file solution.
you guys could help to do a code review with attached two files, or continue discuss better solutions. thanks!

Line 274-279
ShadowsocksController.update.txt

Check and save user configure into a temp file!
Sysproxy.update.txt

Enhanced for log the IO exceptions when read temp conf file
Sysproxy.Update.1.txt

try 816651ebdcaa8571b117864d6fb78cd0a6217362

It works, good job!

Was this page helpful?
0 / 5 - 0 ratings