Merge pull request #36 from asmogo/fix_stuck_conn

close connection on dial error
This commit is contained in:
asmogo 2024-08-28 00:20:09 +02:00 committed by GitHub
commit d11f5573d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,4 @@
NOSTR_RELAYS = 'wss://localhost:7777'#NOSTR_RELAYS = 'ws://localhost:6666' NOSTR_RELAYS = 'ws://0.0.0.0:7777'#NOSTR_RELAYS = 'ws://localhost:6666'
NOSTR_PRIVATE_KEY = "" NOSTR_PRIVATE_KEY = ""
BACKEND_HOST = 'localhost:3338' BACKEND_HOST = 'localhost:3338'
PUBLIC = true PUBLIC = true

View File

@ -270,7 +270,8 @@ func (e *Exit) processMessage(ctx context.Context, msg nostr.IncomingEvent) {
func (e *Exit) handleConnect( func (e *Exit) handleConnect(
ctx context.Context, ctx context.Context,
msg nostr.IncomingEvent, msg nostr.IncomingEvent,
protocolMessage *protocol.Message) { protocolMessage *protocol.Message,
) {
e.mutexMap.Lock(protocolMessage.Key.String()) e.mutexMap.Lock(protocolMessage.Key.String())
defer e.mutexMap.Unlock(protocolMessage.Key.String()) defer e.mutexMap.Unlock(protocolMessage.Key.String())
receiver, err := nip19.EncodeProfile(msg.PubKey, []string{msg.Relay.String()}) receiver, err := nip19.EncodeProfile(msg.PubKey, []string{msg.Relay.String()})
@ -288,6 +289,7 @@ func (e *Exit) handleConnect(
dst, err = net.Dial("tcp", protocolMessage.Destination) dst, err = net.Dial("tcp", protocolMessage.Destination)
if err != nil { if err != nil {
slog.Error("could not connect to backend", "error", err) slog.Error("could not connect to backend", "error", err)
connection.Close()
return return
} }
@ -324,6 +326,7 @@ func (e *Exit) handleConnectReverse(protocolMessage *protocol.Message) {
dst, err = net.Dial("tcp", protocolMessage.Destination) dst, err = net.Dial("tcp", protocolMessage.Destination)
if err != nil { if err != nil {
slog.Error("could not connect to backend", "error", err) slog.Error("could not connect to backend", "error", err)
connection.Close()
return return
} }
slog.Info("connected to entry", "key", protocolMessage.Key) slog.Info("connected to entry", "key", protocolMessage.Key)