mirror of
https://github.com/fatedier/frp.git
synced 2026-05-15 16:15:49 -06:00
[PR #4666] [MERGED] Fix ports not being released on Service.Close() #5020
Labels
No labels
In Progress
WIP
WaitingForInfo
bug
doc
duplicate
easy
enhancement
future
help wanted
invalid
lifecycle/stale
need-issue-template
need-usage-help
no plan
proposal
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/frp#5020
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/fatedier/frp/pull/4666
Author: @ubergeek77
Created: 2/11/2025
Status: ✅ Merged
Merged: 2/12/2025
Merged by: @fatedier
Base:
dev← Head:dev📝 Commits (1)
54ef5baFix ports not being released on Service.Close()📊 Changes
1 file changed (+35 additions, -9 deletions)
View changed files
📝
server/service.go(+35 -9)📄 Description
Description
Service.Close()leaves some listeners open after thefrpsserver is closed, locking the ports until the entire program process is stopped. For CLI users offrps, this isn't an issue because the entire process stops when the server stops. But when usingfrpslike a library, opening a server and then closing it will still leave some ports open. This prevents a newfrpsserver from being opened if one was previously opened and then closed.This PR fixes this by tracking all listeners
frpsopens, then closes them in theClose()function along with the other listeners.Examples
The following code example will start an
frpsserver, stop it, then attempt to start it again.Code example
Without this PR, this will fail because the webserver port,
7500, is still in use:If I disable the webserver in the code example and run it again, the server still fails to start a second time, because port
7000is still in use:With this PR, the previous server exits cleanly, and a new server can be started with no issue:
Notes
I renamed
listenertomuxListenerto disambiguate it from the other types of listeners. It ends up being defined bysvr.muxer.DefaultListener(), so I named it that. This doesn't seem to be a breaking change because no parts of the code try to call the originalsvr.listenerdirectly. But it doesn't matter what any of these are named as long as it gets closed properly.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.