flomesh-io / pipy

Pipy is a programmable proxy for the cloud, edge and IoT.
https://flomesh.io/pipy
Other
775 stars 73 forks source link

[filter] Manually close the Inbound connection got the whole program terminated. #186

Closed yyk808 closed 5 months ago

yyk808 commented 5 months ago

Env

The newest nightly build of pipy on Archlinux.

❯ pipy -v
  Version          : nightly-202406162205
  Commit           : 159d4e82db0367fc138f2427503dfc8ba62dde22
  Commit Date      : Sun, 16 Jun 2024 11:12:56 +0800
  Host             : Linux-6.9.4-zen1-1-zen x86_64
  OpenSSL          : OpenSSL 3.2.0 23 Nov 2023
  Builtin GUI      : Yes
  Builtin Codebases: Yes

Reproduce

First, start a tcp server. Here I use a brief pjs to make it.

pipy -e 'pipy().listen(8080)'

Then, run the pjs code as below: (I put them in a file named test.js)

pipy().task().onStart(new Data).connect("127.0.0.1:8080", {
        // bind: "127.0.0.1:1234", 
        onState: function(conn) {
            if(conn.state=="connected") {
            console.info("Connection: ", conn)
            conn.close()
        }
    }
})

And we shall get:

❯ pipy test.js
  2024-06-17 10:47:00.200 [INF] [config]
  2024-06-17 10:47:00.200 [INF] [config] Module /test.js
  2024-06-17 10:47:00.200 [INF] [config] ===============
  2024-06-17 10:47:00.200 [INF] [config]
  2024-06-17 10:47:00.200 [INF] [config]  [Task #1 ()]
  2024-06-17 10:47:00.200 [INF] [config]  ----->|
  2024-06-17 10:47:00.200 [INF] [config]        |
  2024-06-17 10:47:00.200 [INF] [config]       connect -->|
  2024-06-17 10:47:00.200 [INF] [config]                  |
  2024-06-17 10:47:00.200 [INF] [config]  <---------------|
  2024-06-17 10:47:00.200 [INF] [config]  
  2024-06-17 10:47:00.200 [INF] Connection:  { state: "connected", socket: {  }, localAddress: "127.0.0.1", localPort: 42718, remoteAddress: "", remotePort: 8080 }
  terminate called after throwing an instance of 'std::system_error'
    what():  set_option: Bad file descriptor
  zsh: IOT instruction (core dumped)  pipy test.js

The disconnection packets sent correctly. 图片

I found the usage in ztm: agent/mesh.js The function call there SHOULD work fine though I didn't strictly test yet. However, I think a single call causing the termination of program should still be considered as a bug.

pajama-coder commented 5 months ago

This issue is fixed in 773ec5eb995fc46da54b8c665894968d501bf653. Thanks for finding and reporting the bug.