Skip to content

Set a read timeout for the event server clients and event payload - #309

Open
myselfBZ wants to merge 3 commits into
azimjohn:masterfrom
myselfBZ:event-server-readtimeout
Open

Set a read timeout for the event server clients and event payload #309
myselfBZ wants to merge 3 commits into
azimjohn:masterfrom
myselfBZ:event-server-readtimeout

Conversation

@myselfBZ

@myselfBZ myselfBZ commented Aug 7, 2026

Copy link
Copy Markdown

hi @azimjohn, this pr fixes #307.

  1. serveEventConn() method now sets a read time out when awaiting TunnRequested event.
    Like the servePublicConn it waits 3 seconds before cutting off the connection. It does not let arbitary clients connect and hang in the event server.
  2. there's now a maximum length limit on events, 1KB.
  3. conn.Read() is no longer used, because data can come in chunks, so it's not guaranteed the Read method will read it in one go. io.ReadFull is introduced to solve this problem.
    The changes have been stress tested on a live self-hosted server with the following script.
func main() {
	var wg sync.WaitGroup
	for i := 1; i < 1500; i++ {
		if i % 100 == 0 {
			log.Printf("opened %d connections", i)
		}
		wg.Add(1)
		go func() {
			defer wg.Done()
			conn, err := net.Dial("tcp", "[MY_SELF_HOSTED_SERVER]") // cannot be disclosed
			if err != nil {
				log.Fatal("dial error:", err)
			}
			length := make([]byte, 2)
			binary.LittleEndian.PutUint16(length, uint16(1024))
			if _, err := conn.Write(length); err != nil {
				log.Fatal("error writing length:", err)
			}
			time.Sleep(time.Second * 5)
			buff := make([]byte, 1024)
			if _, err := conn.Read(buff); err != nil {
				log.Println("error reading to the connection:", err)
			}
		}()
	}
	wg.Wait()
}

everything errored out as expected, after the server closed the connection because of timeout.
Also, i tested the server with jprq's cli manually and there were no issues with opening and moving data through tunnels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource exhaustion vulnerability

1 participant