[GH-ISSUE #2219] Using server plug-in to communicate with Flask app #1766

Closed
opened 2026-05-05 13:08:20 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @charlee-cz on GitHub (Jan 25, 2021).
Original GitHub issue: https://github.com/fatedier/frp/issues/2219

[REQUIRED] hat version of frp are you using

Version: 0.34.3 for both client and server

[REQUIRED] What operating system and processor architecture are you using
OS: Ubuntu 20.04.1 LTS (server), Raspberry Pi on Raspberry Pi OS (client)
CPU architecture:

[REQUIRED] description of errors

confile

# frps.ini
[common]
bind_port = 10000
allow_ports = 12000-12050

max_pool_count = 1000

[plugin.port-manager]
addr = localhost:3222
path = /handler
ops = NewUserConn, NewWorkConn, NewProxy
# frpc.ini
[common]
server_addr = x.x.x.x
server_port = 10000
admin_port = 1089

user = name
use_encryption = true
tls_enable = true

[name]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 0

log file

# frpc
2021/01/25 14:28:30 [I] [service.go:288] [35a8438f7701e96f] login to server success, get run id [35a8438f7701e96f], server udp port [0]
2021/01/25 14:28:30 [I] [proxy_manager.go:144] [35a8438f7701e96f] proxy added: [name.name]
2021/01/25 14:28:30 [I] [service.go:134] admin server listen on 127.0.0.1:1089
2021/01/25 14:28:30 [W] [control.go:178] [35a8438f7701e96f] [] start error: proxy [] not found
# Loops through
2021/01/25 14:35:11 [W] [control.go:178] [06c235b24453dbef] [] start error: proxy [] not found
# frps
2021/01/25 22:28:27 [I] [service.go:149] plugin [port-manager] has been registered
2021/01/25 22:28:27 [I] [service.go:190] frps tcp listen on 0.0.0.0:10000
2021/01/25 22:28:27 [I] [service.go:289] Dashboard listen on 0.0.0.0:7500
2021/01/25 22:28:27 [I] [root.go:215] start frps success
2021/01/25 22:28:30 [I] [service.go:444] [35a8438f7701e96f] client login info: ip [162.156.7.79:34728] version [0.34.3] hostname [] os [linux] arch [arm]
2021/01/25 22:28:30 [I] [tcp.go:63] [35a8438f7701e96f] [] tcp proxy listen port [0]
2021/01/25 22:28:30 [I] [control.go:446] [35a8438f7701e96f] new proxy [] success
2021/01/25 22:28:51 [I] [tcp.go:63] [35a8438f7701e96f] [] tcp proxy listen port [0]
2021/01/25 22:28:51 [I] [proxy.go:87] [35a8438f7701e96f] [] proxy closing
2021/01/25 22:28:51 [I] [proxy.go:159] [35a8438f7701e96f] [] listener is closed
# After a while....
2021/01/25 22:28:51 [W] [control.go:442] [35a8438f7701e96f] new proxy [] error: proxy name [] is already in use
# Loops through these last two lines:
2021/01/25 22:34:29 [I] [proxy.go:159] [06c235b24453dbef] [] listener is closed
2021/01/25 22:34:50 [I] [tcp.go:63] [06c235b24453dbef] [] tcp proxy listen port [0]
2021/01/25 22:34:50 [I] [proxy.go:87] [06c235b24453dbef] [] proxy closing
2021/01/25 22:34:50 [I] [proxy.go:159] [06c235b24453dbef] [] listener is closed
2021/01/25 22:34:50 [W] [control.go:442] [06c235b24453dbef] new proxy [] error: proxy name [] is already in use

Steps to reproduce the issue

  1. Run Flask app on specified port and path for plug-in
  2. Run ./frps with the init above
  3. Run ./frpc on another machine with the init specified above

Supplementary information

My Flask app currently checks the request for ['op'] then matches a function based on what operation is sent. Each function currently returns a JSON converted dictionary for allow without modfication as specified in your documentation. So:

'{
    "reject": false,
    "unchange": true
}'

Currently it seems like NewProxy runs into a bug in returning the response. I am able to get the request:

{'user': {'user': 'name', 'metas': {}, 'run_id': '35a8438f7701e96f'}, 'proxy_name': 'name.name', 'proxy_type': 'tcp', 'use_encryption': False, 'use_compression': False, 'group': '', 'group_key': '', 'metas': {}, 'remote_port': 0, 'custom_domains': None, 'subdomain': '', 'locations': None, 'http_user': '', 'http_pwd': '', 'host_header_rewrite': '', 'headers': None, 'sk': '', 'multiplexer': ''}

But then I encounter the proxy name [] is already in use error even though I have my Flask app return the unchange: true JSON response. I have it manually set to always return that string with a 200 HTTP code.

I am also never getting responses for NewWorkConn on the Flask side. Maybe I'm understanding the documentation wrong but I was under the assumption this is triggered when frpc connects to frps.

My rationale: I want to be able to let frpc connect to random remote ports for tcp via remote_port: 0, and have the frps server find out what port it ends up being without the use of the admin portal or without having to manually gain access to the frpc machine (as I want to be able to manage this automatically). As of now, it doesn't seem like the NewProxy operation automatically tells me what port it is, but I was thinking that I could just have this be handled on the Flask side if needed be (haven't been able to get it to work, so just wanted to fix this bug before trying that).

If there is a much simpler way to handle this, I would much appreciate help on that end.

Can you guess what caused this issue
Maybe I'm understanding the plug-in wrong and making mistakes in my Flask app (not quite experienced in writing server endpoints), but not sure what is causing the issue.

My Flask app currently causes no issues with the Ping or NewUserConn operations using the same return result

Checklist:

  • I included all information required in the sections above
  • I made sure there are no duplicates of this report (Use Search)
Originally created by @charlee-cz on GitHub (Jan 25, 2021). Original GitHub issue: https://github.com/fatedier/frp/issues/2219 <!-- From Chinese to English by machine translation, welcome to revise and polish. --> <!-- ⚠️⚠️ Incomplete reports will be marked as invalid, and closed, with few exceptions ⚠️⚠️ --> <!-- in addition, please use search well so that the same solution can be found in the feedback, we will close it directly --> <!-- for convenience of differentiation, use FRPS or FRPC to refer to the FRP server or client --> **[REQUIRED] hat version of frp are you using** <!-- Use ./frpc -v or ./frps -v --> Version: 0.34.3 for both client and server **[REQUIRED] What operating system and processor architecture are you using** OS: Ubuntu 20.04.1 LTS (server), Raspberry Pi on Raspberry Pi OS (client) CPU architecture: **[REQUIRED] description of errors** **confile** ```Bash # frps.ini [common] bind_port = 10000 allow_ports = 12000-12050 max_pool_count = 1000 [plugin.port-manager] addr = localhost:3222 path = /handler ops = NewUserConn, NewWorkConn, NewProxy ``` ```Bash # frpc.ini [common] server_addr = x.x.x.x server_port = 10000 admin_port = 1089 user = name use_encryption = true tls_enable = true [name] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 0 ``` <!-- Please pay attention to hiding the token, server_addr and other privacy information --> **log file** ``` # frpc 2021/01/25 14:28:30 [I] [service.go:288] [35a8438f7701e96f] login to server success, get run id [35a8438f7701e96f], server udp port [0] 2021/01/25 14:28:30 [I] [proxy_manager.go:144] [35a8438f7701e96f] proxy added: [name.name] 2021/01/25 14:28:30 [I] [service.go:134] admin server listen on 127.0.0.1:1089 2021/01/25 14:28:30 [W] [control.go:178] [35a8438f7701e96f] [] start error: proxy [] not found # Loops through 2021/01/25 14:35:11 [W] [control.go:178] [06c235b24453dbef] [] start error: proxy [] not found ``` ``` # frps 2021/01/25 22:28:27 [I] [service.go:149] plugin [port-manager] has been registered 2021/01/25 22:28:27 [I] [service.go:190] frps tcp listen on 0.0.0.0:10000 2021/01/25 22:28:27 [I] [service.go:289] Dashboard listen on 0.0.0.0:7500 2021/01/25 22:28:27 [I] [root.go:215] start frps success 2021/01/25 22:28:30 [I] [service.go:444] [35a8438f7701e96f] client login info: ip [162.156.7.79:34728] version [0.34.3] hostname [] os [linux] arch [arm] 2021/01/25 22:28:30 [I] [tcp.go:63] [35a8438f7701e96f] [] tcp proxy listen port [0] 2021/01/25 22:28:30 [I] [control.go:446] [35a8438f7701e96f] new proxy [] success 2021/01/25 22:28:51 [I] [tcp.go:63] [35a8438f7701e96f] [] tcp proxy listen port [0] 2021/01/25 22:28:51 [I] [proxy.go:87] [35a8438f7701e96f] [] proxy closing 2021/01/25 22:28:51 [I] [proxy.go:159] [35a8438f7701e96f] [] listener is closed # After a while.... 2021/01/25 22:28:51 [W] [control.go:442] [35a8438f7701e96f] new proxy [] error: proxy name [] is already in use # Loops through these last two lines: 2021/01/25 22:34:29 [I] [proxy.go:159] [06c235b24453dbef] [] listener is closed 2021/01/25 22:34:50 [I] [tcp.go:63] [06c235b24453dbef] [] tcp proxy listen port [0] 2021/01/25 22:34:50 [I] [proxy.go:87] [06c235b24453dbef] [] proxy closing 2021/01/25 22:34:50 [I] [proxy.go:159] [06c235b24453dbef] [] listener is closed 2021/01/25 22:34:50 [W] [control.go:442] [06c235b24453dbef] new proxy [] error: proxy name [] is already in use ``` **Steps to reproduce the issue** 1. Run Flask app on specified port and path for plug-in 2. Run `./frps` with the init above 3. Run `./frpc` on another machine with the init specified above **Supplementary information** My Flask app currently checks the request for `['op']` then matches a function based on what operation is sent. Each function currently returns a JSON converted dictionary for `allow` without modfication as specified in [your documentation](https://github.com/fatedier/frp/blob/dev/doc/server_plugin.md). So: ``` '{ "reject": false, "unchange": true }' ``` Currently it seems like NewProxy runs into a bug in returning the response. I am able to get the request: ``` {'user': {'user': 'name', 'metas': {}, 'run_id': '35a8438f7701e96f'}, 'proxy_name': 'name.name', 'proxy_type': 'tcp', 'use_encryption': False, 'use_compression': False, 'group': '', 'group_key': '', 'metas': {}, 'remote_port': 0, 'custom_domains': None, 'subdomain': '', 'locations': None, 'http_user': '', 'http_pwd': '', 'host_header_rewrite': '', 'headers': None, 'sk': '', 'multiplexer': ''} ``` But then I encounter the `proxy name [] is already in use` error even though I have my Flask app return the `unchange: true` JSON response. I have it manually set to always return that string with a 200 HTTP code. I am also never getting responses for NewWorkConn on the Flask side. Maybe I'm understanding the documentation wrong but I was under the assumption this is triggered when `frpc` connects to `frps`. My rationale: I want to be able to let `frpc` connect to random remote ports for tcp via `remote_port: 0`, and have the `frps` server find out what port it ends up being without the use of the admin portal or without having to manually gain access to the `frpc` machine (as I want to be able to manage this automatically). As of now, it doesn't seem like the `NewProxy` operation automatically tells me what port it is, but I was thinking that I could just have this be handled on the Flask side if needed be (haven't been able to get it to work, so just wanted to fix this bug before trying that). If there is a much simpler way to handle this, I would much appreciate help on that end. **Can you guess what caused this issue** Maybe I'm understanding the plug-in wrong and making mistakes in my Flask app (not quite experienced in writing server endpoints), but not sure what is causing the issue. > My Flask app currently causes no issues with the `Ping` or `NewUserConn` operations using the same return result **Checklist**: <!--- Make sure you've completed the following steps (put an "X" between of brackets): --> - [X] I included all information required in the sections above - [X] I made sure there are no duplicates of this report [(Use Search)](https://github.com/fatedier/frp/issues?q=is%3Aissue)
gitea-mirror 2026-05-05 13:08:20 -06:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@charlee-cz commented on GitHub (Jan 26, 2021):

Another quick question:

when frpc uses remote_port:0, the JSON string sent through the server plug-in also sends remote_port:0. Is there a way to get the actual port being used?

<!-- gh-comment-id:767900871 --> @charlee-cz commented on GitHub (Jan 26, 2021): Another quick question: when frpc uses `remote_port:0`, the JSON string sent through the server plug-in also sends `remote_port:0`. Is there a way to get the actual port being used?
Author
Owner

@fatedier commented on GitHub (Jan 27, 2021):

@CharLee674
You can assign the port in your plugin, or get this port from frps HTTP API after the proxy started.

<!-- gh-comment-id:768001537 --> @fatedier commented on GitHub (Jan 27, 2021): @CharLee674 You can assign the port in your plugin, or get this port from frps HTTP API after the proxy started.
Author
Owner

@charlee-cz commented on GitHub (Jan 27, 2021):

Oh ok thanks! Not sure why I didn't try the second option first. Is there documentation on the HTTP API endpoints? I know I can figure it out myself but just wondering.

<!-- gh-comment-id:768616309 --> @charlee-cz commented on GitHub (Jan 27, 2021): Oh ok thanks! Not sure why I didn't try the second option first. Is there documentation on the HTTP API endpoints? I know I can figure it out myself but just wondering.
Author
Owner

@fatedier commented on GitHub (Jan 28, 2021):

@CharLee674 No documents for that now. It's only used in frp dashboard and not elegant. We want to refeactor it future.

<!-- gh-comment-id:768768910 --> @fatedier commented on GitHub (Jan 28, 2021): @CharLee674 No documents for that now. It's only used in frp dashboard and not elegant. We want to refeactor it future.
Author
Owner

@yuyulei commented on GitHub (Feb 5, 2021):

@CharLee674 I tested as you said, but failed to reproduce it.

I found 2 proxies(35a8438f7701e96f, 06c235b24453dbef) in your log, they have same proxy name ?

image

<!-- gh-comment-id:773760239 --> @yuyulei commented on GitHub (Feb 5, 2021): @CharLee674 I tested as you said, but failed to reproduce it. I found 2 proxies(35a8438f7701e96f, 06c235b24453dbef) in your log, they have same proxy name ? ![image](https://user-images.githubusercontent.com/18277081/106985799-0c62d300-67a5-11eb-945f-dd9e9628326e.png)
Author
Owner

@charlee-cz commented on GitHub (Feb 5, 2021):

Sorry for forgetting to update, but I did try an alternate flask app and it seemed to work fine there. Most likely an issue on my end. I'll close this issue now

<!-- gh-comment-id:773798735 --> @charlee-cz commented on GitHub (Feb 5, 2021): Sorry for forgetting to update, but I did try an alternate flask app and it seemed to work fine there. Most likely an issue on my end. I'll close this issue now
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#1766
No description provided.