[GH-ISSUE #4766] frp似乎会代替TCP服务端回复[FIN ACK]? #3763

Closed
opened 2026-05-05 14:24:47 -06:00 by gitea-mirror · 2 comments
Owner

Originally created by @Curtion on GitHub (Apr 24, 2025).
Original GitHub issue: https://github.com/fatedier/frp/issues/4766

Bug Description

frp在收到客户端FIN后会好像直接回复[FIN ACK], 从而导致后续数据包服务端无法正常发送给客户端。这里给出一个客户端和服务端的示例代码,如果在本地连接则正常,如果通过FRP转发则异常

frpc Version

0.62.0

frps Version

0.62.0

System Architecture

frps:linux/amd64; frpc:windows/amd64

Configurations

服务端代码:

package main

import (
	"fmt"
	"net"
)

func main() {
	listener, err := net.Listen("tcp", "127.0.0.1:21000")
	if err != nil {
		fmt.Println("Error listening:", err.Error())
		return
	}
	defer listener.Close()
	fmt.Println("Server listening on :21000")

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Println("Error accepting:", err.Error())
			continue
		}
		go handleRequest(conn)
	}
}

func handleRequest(conn net.Conn) {
	defer conn.Close()

	buf := make([]byte, 1024)
	n, err := conn.Read(buf)
	if err != nil {
		fmt.Println("Error reading:", err.Error())
		return
	}

	data := string(buf[:n])
	fmt.Printf("Received from client: %s\n", data)

	_, err = conn.Write([]byte("Server received: " + data))
	if err != nil {
		fmt.Println("Error writing:", err.Error())
	}
}

客户端代码:

package main

import (
	"fmt"
	"net"
)

func main() {
	// conn, err := net.Dial("tcp", "127.0.0.1:21000")
	conn, err := net.Dial("tcp", "server:21666")
	if err != nil {
		fmt.Println("Error connecting:", err.Error())
		return
	}
	defer conn.Close()

	message := "hello"
	_, err = conn.Write([]byte(message))
	if err != nil {
		fmt.Println("Error sending:", err.Error())
		return
	}

	// Close write side to signal we're done sending
	tcpConn := conn.(*net.TCPConn)
	tcpConn.CloseWrite()

	buf := make([]byte, 1024)
	n, err := conn.Read(buf)
	if err != nil {
		fmt.Println("Error receiving:", err.Error())
		return
	}

	fmt.Printf("Server response: %s\n", string(buf[:n]))
}

Logs

Image

Image

Image

Steps to reproduce

TCP客户端在发送数据后立即关闭写入, 例如:

	tcpConn := conn.(*net.TCPConn)
	tcpConn.CloseWrite()

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @Curtion on GitHub (Apr 24, 2025). Original GitHub issue: https://github.com/fatedier/frp/issues/4766 ### Bug Description frp在收到客户端FIN后会好像直接回复[FIN ACK], 从而导致后续数据包服务端无法正常发送给客户端。这里给出一个客户端和服务端的示例代码,如果在本地连接则正常,如果通过FRP转发则异常 ### frpc Version 0.62.0 ### frps Version 0.62.0 ### System Architecture frps:linux/amd64; frpc:windows/amd64 ### Configurations 服务端代码: ```go package main import ( "fmt" "net" ) func main() { listener, err := net.Listen("tcp", "127.0.0.1:21000") if err != nil { fmt.Println("Error listening:", err.Error()) return } defer listener.Close() fmt.Println("Server listening on :21000") for { conn, err := listener.Accept() if err != nil { fmt.Println("Error accepting:", err.Error()) continue } go handleRequest(conn) } } func handleRequest(conn net.Conn) { defer conn.Close() buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Error reading:", err.Error()) return } data := string(buf[:n]) fmt.Printf("Received from client: %s\n", data) _, err = conn.Write([]byte("Server received: " + data)) if err != nil { fmt.Println("Error writing:", err.Error()) } } ``` 客户端代码: ```go package main import ( "fmt" "net" ) func main() { // conn, err := net.Dial("tcp", "127.0.0.1:21000") conn, err := net.Dial("tcp", "server:21666") if err != nil { fmt.Println("Error connecting:", err.Error()) return } defer conn.Close() message := "hello" _, err = conn.Write([]byte(message)) if err != nil { fmt.Println("Error sending:", err.Error()) return } // Close write side to signal we're done sending tcpConn := conn.(*net.TCPConn) tcpConn.CloseWrite() buf := make([]byte, 1024) n, err := conn.Read(buf) if err != nil { fmt.Println("Error receiving:", err.Error()) return } fmt.Printf("Server response: %s\n", string(buf[:n])) } ``` ### Logs ![Image](https://github.com/user-attachments/assets/18b9fea8-c9d3-4256-812c-c9809330b5a9) ![Image](https://github.com/user-attachments/assets/f2330849-6287-49d1-9651-bbd0c17a0762) ![Image](https://github.com/user-attachments/assets/82dde0b6-8028-4f66-a243-9afefd51c351) ### Steps to reproduce TCP客户端在发送数据后立即关闭写入, 例如: ```go tcpConn := conn.(*net.TCPConn) tcpConn.CloseWrite() ``` ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [x] Others
gitea-mirror 2026-05-05 14:24:47 -06:00
Author
Owner

@xqzr commented on GitHub (Apr 25, 2025):

frp 会终结 TCP

<!-- gh-comment-id:2830754569 --> @xqzr commented on GitHub (Apr 25, 2025): frp 会终结 TCP
Author
Owner

@github-actions[bot] commented on GitHub (May 10, 2025):

Issues go stale after 14d of inactivity. Stale issues rot after an additional 3d of inactivity and eventually close.

<!-- gh-comment-id:2868150293 --> @github-actions[bot] commented on GitHub (May 10, 2025): Issues go stale after 14d of inactivity. Stale issues rot after an additional 3d of inactivity and eventually close.
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#3763
No description provided.