[GH-ISSUE #256] During startup, can frpc retry if error on server connection? #182

Closed
opened 2026-05-05 11:56:09 -06:00 by gitea-mirror · 10 comments
Owner

Originally created by @yydcool on GitHub (Feb 17, 2017).
Original GitHub issue: https://github.com/fatedier/frp/issues/256

The case happens when I start frps later than frpc.
frpc will try to connect server, but the frps is not running yet. So frpc print "connect to server failed!" then exit.
Refer to code in frpc/control.go func ControlProcess(cli *client.ProxyClient, wait *sync.WaitGroup)

	c, err := loginToServer(cli)
	if err != nil {
		log.Error("ProxyName [%s], connect to server failed!", cli.Name)
		return
	}

Would it be better to have a while loop here? always retry until connected to server (also wait (e.g. 10s) between each retry)

Originally created by @yydcool on GitHub (Feb 17, 2017). Original GitHub issue: https://github.com/fatedier/frp/issues/256 The case happens when I start frps later than frpc. frpc will try to connect server, but the frps is not running yet. So frpc print "connect to server failed!" then exit. Refer to code in frpc/control.go func ControlProcess(cli *client.ProxyClient, wait *sync.WaitGroup) ``` c, err := loginToServer(cli) if err != nil { log.Error("ProxyName [%s], connect to server failed!", cli.Name) return } ``` Would it be better to have a while loop here? always retry until connected to server (also wait (e.g. 10s) between each retry)
Author
Owner

@cxx8294 commented on GitHub (Feb 17, 2017):

请讲普通话

<!-- gh-comment-id:280553852 --> @cxx8294 commented on GitHub (Feb 17, 2017): 请讲普通话
Author
Owner

@fatedier commented on GitHub (Feb 17, 2017):

@yydcool Users may set wrong server ip or port, and it will never connect success. So i think it's better to feedback the error and exit.

<!-- gh-comment-id:280556227 --> @fatedier commented on GitHub (Feb 17, 2017): @yydcool Users may set wrong server ip or port, and it will never connect success. So i think it's better to feedback the error and exit.
Author
Owner

@fatedier commented on GitHub (Feb 17, 2017):

@cxx8294 Github 上推荐用英语,方便各个国家的使用者共同交流,只要别人能看懂就行了。

<!-- gh-comment-id:280556376 --> @fatedier commented on GitHub (Feb 17, 2017): @cxx8294 Github 上推荐用英语,方便各个国家的使用者共同交流,只要别人能看懂就行了。
Author
Owner

@soldierssword commented on GitHub (Feb 27, 2018):

但是有时候需要重启公网的frps来重新加载配置文件,如果不自动重连的话那就很麻烦了,希望在启动参数中加入失败重试。

<!-- gh-comment-id:368711295 --> @soldierssword commented on GitHub (Feb 27, 2018): 但是有时候需要重启公网的frps来重新加载配置文件,如果不自动重连的话那就很麻烦了,希望在启动参数中加入失败重试。
Author
Owner

@baixiaoshengofficial commented on GitHub (Oct 23, 2018):

建议新加参数,让用户承担后果吧~
当前的情况是,FRPS似乎因为内存的问题导致服务器崩了,重启了服务器之后,人不在FRPC的环境没办法远程遥控FRPC重启,就造成了一个连不上FRPS的死局···

<!-- gh-comment-id:432109060 --> @baixiaoshengofficial commented on GitHub (Oct 23, 2018): 建议新加参数,让用户承担后果吧~ 当前的情况是,FRPS似乎因为内存的问题导致服务器崩了,重启了服务器之后,人不在FRPC的环境没办法远程遥控FRPC重启,就造成了一个连不上FRPS的死局···
Author
Owner

@fantasydr commented on GitHub (Mar 11, 2019):

If you're using systemd to launch frps, add something like this in the systemd conf file:

[Service]
Restart=on-failure    
RestartSec=5s

A hint for someone like me newly to the frps and systemd.

<!-- gh-comment-id:471383161 --> @fantasydr commented on GitHub (Mar 11, 2019): If you're using systemd to launch frps, add something like this in the systemd conf file: ``` [Service] Restart=on-failure RestartSec=5s ``` A hint for someone like me newly to the frps and systemd.
Author
Owner

@HomeLH commented on GitHub (Mar 20, 2019):

A configurable retry entry is helpful for embedding devices, because their network service such as 4G may not be stable.

<!-- gh-comment-id:474729157 --> @HomeLH commented on GitHub (Mar 20, 2019): A configurable retry entry is helpful for embedding devices, because their network service such as 4G may not be stable.
Author
Owner

@HomeLH commented on GitHub (Mar 20, 2019):

If you're using systemd to launch frps, add something like this in the systemd conf file:

[Service]
Restart=on-failure    
RestartSec=5s

A hint for someone like me newly to the frps and systemd.

Thanks a lot. This method works well. It will retry every "RestartSec“.

<!-- gh-comment-id:474732683 --> @HomeLH commented on GitHub (Mar 20, 2019): > > > If you're using systemd to launch frps, add something like this in the systemd conf file: > > ``` > [Service] > Restart=on-failure > RestartSec=5s > ``` > > A hint for someone like me newly to the frps and systemd. Thanks a lot. This method works well. It will retry every "RestartSec“.
Author
Owner

@Marcocxy commented on GitHub (Aug 23, 2022):

If you're using systemd to launch frps, add something like this in the systemd conf file:

[Service]
Restart=on-failure    
RestartSec=5s

A hint for someone like me newly to the frps and systemd.

Any idea for frpc(frp client)? The topic was frpc not frps.

<!-- gh-comment-id:1223505493 --> @Marcocxy commented on GitHub (Aug 23, 2022): > If you're using systemd to launch frps, add something like this in the systemd conf file: > > ``` > [Service] > Restart=on-failure > RestartSec=5s > ``` > > A hint for someone like me newly to the frps and systemd. Any idea for frpc(frp client)? The topic was frpc not frps.
Author
Owner

@axmmisaka commented on GitHub (Dec 31, 2022):

If you're using systemd to launch frps, add something like this in the systemd conf file:

[Service]
Restart=on-failure    
RestartSec=5s

A hint for someone like me newly to the frps and systemd.

Any idea for frpc(frp client)? The topic was frpc not frps.

You could, if you want, write a wrapper script in powershell like this

$ISSUE = $true
while ($ISSUE) {
    ./frpc @args
    if ($LastExitCode -eq 0) {
        $ISSUE = $false
    }
}

or a comparable script in bash to make it keep trying.
That said I ran into similar problems and it might be a good feature to add, although it certainly could be solved externally; I'm using nssm on windows and the restart logic is such a pita

如果你想的话,可以写个上面贴的这种执行脚本或者bash中类似的脚本让程序失败后重试
不过我最近遇到了类似的问题,虽然这个问题可以用外部工具解决,我觉得可能也是个可以加入的好特性;我在windows上用nssm,重启逻辑是真的高血压

<!-- gh-comment-id:1368180280 --> @axmmisaka commented on GitHub (Dec 31, 2022): > > If you're using systemd to launch frps, add something like this in the systemd conf file: > > ``` > > [Service] > > Restart=on-failure > > RestartSec=5s > > ``` > > A hint for someone like me newly to the frps and systemd. > > Any idea for frpc(frp client)? The topic was frpc not frps. You could, if you want, write a wrapper script in powershell like this ```powershell $ISSUE = $true while ($ISSUE) { ./frpc @args if ($LastExitCode -eq 0) { $ISSUE = $false } } ``` or a comparable script in bash to make it keep trying. That said I ran into similar problems and it might be a good feature to add, although it certainly could be solved externally; I'm using nssm on windows and the restart logic is such a pita 如果你想的话,可以写个上面贴的这种执行脚本或者bash中类似的脚本让程序失败后重试 不过我最近遇到了类似的问题,虽然这个问题可以用外部工具解决,我觉得可能也是个可以加入的好特性;我在windows上用nssm,重启逻辑是真的高血压
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#182
No description provided.