flashmob / go-guerrilla

Mini SMTP server written in golang
MIT License
2.76k stars 361 forks source link

Connections are getting closed immediately #123

Closed sajan45 closed 5 years ago

sajan45 commented 6 years ago

I am trying to use go-guerrilla as a package and I should mention that I am new to Golang too. The app is running inside a docker container and go-guerrilla is listening to interface 127.0.0.1:2525 , which is mapped to port 25 on my host machine. With log level set to debug, I got messages "[127.0.0.1:2525] Waiting for a new client. Next Client ID: 1". But when I try to access the port 25 by telnet, the connections are getting closed immediately without any information in logs. Below is the output from telnet.

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

I am sure this is not related to my local system only as I can not telnet to my cloud server too. Tried accessing through some other cloud platforms and they gave the same error too. So , nothing my ISP blocking or something like that. Any help is appreciated.

flashmob commented 6 years ago

Perhaps try a higher timeout setting in the config.

On Fri., 21 Sep. 2018, 00:41 Sajan, notifications@github.com wrote:

I am trying to use go-guerrilla as a package and I should mention that I am new to Golang too. The app is running inside a docker container and go-guerrilla is listening to interface 127.0.0.1:2525 , which is mapped to port 25 on my host machine. With log level set to debug, I got messages "[127.0.0.1:2525] Waiting for a new client. Next Client ID: 1". But when I try to access the port 25 by telnet, the connections are getting closed immediately without any information in logs. Below is the output from telnet.

Connected to localhost. Escape character is '^]'. Connection closed by foreign host.```

I am sure this is not related to my local system only as I can not telnet to my cloud server too. Tried accessing through some other cloud platforms and they gave the same error too. So , nothing my ISP blocking or something like that. Any help is appreciated.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/flashmob/go-guerrilla/issues/123, or mute the thread https://github.com/notifications/unsubscribe-auth/AAnmP1lorheefw9nuRA7BO4fVGGbgPUYks5uc6kOgaJpZM4WyR2v .

sajan45 commented 6 years ago

The default connection timeout for a server is 30 seconds, but my connections got closed instantly. Any other timeout setting I am missing?

artpar commented 5 years ago

@sajan45 how did you solve this ? apologies for posting on a old issue.

sajan45 commented 5 years ago

@artpar I am sorry, I don't remember how I did I solve this or I ever solved it. I was just experimenting at that time, so abandoned the pet project due to lack of time.

flashmob commented 5 years ago

Hi @sajan45 Are you using this as a package? Please point to a gist/repo to your example code. Also, are you able to run tests in the go-guerrilla repo? Please cd to there and type make test

artpar commented 5 years ago

@flashmob I am actually able to connect locally on my machine (server running locally) but get a immediate connection close if I try it on linode or digitalocean.

I did see where @sajan45 was using the package: https://github.com/sajan45/daak/commits/master

artpar commented 5 years ago

I ran tests on linode server, one test fails but I don't think that's relevant to this:


go test -v .
=== RUN   TestSMTP
time="2019-03-20T09:32:32Z" level=debug msg="making servers"
time="2019-03-20T09:32:32Z" level=info msg="Starting: 127.0.0.1:2525"
time="2019-03-20T09:32:32Z" level=info msg="Listening on TCP 127.0.0.1:2525"
time="2019-03-20T09:32:32Z" level=debug msg="[127.0.0.1:2525] Waiting for a new client. Next Client ID: 1"
time="2019-03-20T09:32:32Z" level=info msg="main log configured to stderr"
time="2019-03-20T09:32:32Z" level=info msg="processing worker started (#1)"
time="2019-03-20T09:32:34Z" level=info msg="Server [127.0.0.1:2525] has stopped accepting new clients"
time="2019-03-20T09:32:34Z" level=info msg="shutting down pool [127.0.0.1:2525]"
time="2019-03-20T09:32:34Z" level=info msg="shutdown completed for [127.0.0.1:2525]"
time="2019-03-20T09:32:34Z" level=info msg="stop signal for worker (#1)"
time="2019-03-20T09:32:34Z" level=info msg="Backend shutdown completed"
--- PASS: TestSMTP (2.00s)
=== RUN   TestSMTPNoLog
--- PASS: TestSMTPNoLog (2.00s)
=== RUN   TestSMTPCustomServer
--- PASS: TestSMTPCustomServer (2.00s)
=== RUN   TestSMTPCustomBackend
--- PASS: TestSMTPCustomBackend (2.00s)
=== RUN   TestSMTPLoadFile
--- PASS: TestSMTPLoadFile (2.03s)
=== RUN   TestReopenLog
--- PASS: TestReopenLog (2.01s)
=== RUN   TestSetConfig
--- PASS: TestSetConfig (2.01s)
=== RUN   TestSetConfigError
--- PASS: TestSetConfigError (0.00s)
=== RUN   TestSetAddProcessor
--- PASS: TestSetAddProcessor (1.03s)
=== RUN   TestReloadConfig
time="2019-03-20T09:32:47Z" level=debug msg="making servers"
time="2019-03-20T09:32:47Z" level=info msg="Starting: 127.0.0.1:2525"
time="2019-03-20T09:32:47Z" level=info msg="Listening on TCP 127.0.0.1:2525"
time="2019-03-20T09:32:47Z" level=debug msg="[127.0.0.1:2525] Waiting for a new client. Next Client ID: 1"
time="2019-03-20T09:32:47Z" level=info msg="main log configured to stderr"
time="2019-03-20T09:32:47Z" level=info msg="Configuration was reloaded at 0001-01-01 00:00:00 +0000 UTC"
time="2019-03-20T09:32:47Z" level=info msg="processing worker started (#1)"
time="2019-03-20T09:32:47Z" level=info msg="stop signal for worker (#1)"
time="2019-03-20T09:32:47Z" level=info msg="allowed_hosts config changed, a new list was set"
--- PASS: TestReloadConfig (0.01s)
=== RUN   TestPubSubAPI
--- PASS: TestPubSubAPI (0.02s)
=== RUN   TestAPILog
time="2019-03-20T09:32:47Z" level=info msg=logtest1
--- PASS: TestAPILog (0.00s)
=== RUN   TestSkipAllowsHost
--- PASS: TestSkipAllowsHost (1.00s)
=== RUN   TestCustomBackendResult
--- PASS: TestCustomBackendResult (1.02s)
=== RUN   TestConfigLoad
--- PASS: TestConfigLoad (0.02s)
=== RUN   TestSampleConfig
--- PASS: TestSampleConfig (0.00s)
=== RUN   TestConfigChangeEvents
--- PASS: TestConfigChangeEvents (1.51s)
=== RUN   TestTLSConfig
--- PASS: TestTLSConfig (0.00s)
=== RUN   TestHandleClient
--- PASS: TestHandleClient (0.00s)
=== RUN   TestXClient
--- PASS: TestXClient (0.01s)
=== RUN   TestGatewayTimeout
--- PASS: TestGatewayTimeout (5.00s)
=== RUN   TestGatewayPanic
--- PASS: TestGatewayPanic (3.00s)
=== RUN   TestAllowsHosts
--- PASS: TestAllowsHosts (0.00s)
PASS
ok      github.com/flashmob/go-guerrilla    26.709s
go test -v ./tests
=== RUN   TestStart
--- PASS: TestStart (1.01s)
=== RUN   TestGreeting
--- PASS: TestGreeting (0.02s)
=== RUN   TestShutDown
--- PASS: TestShutDown (0.41s)
=== RUN   TestRFC2821LimitRecipients
--- PASS: TestRFC2821LimitRecipients (0.18s)
=== RUN   TestRFC2832LimitLocalPart
--- PASS: TestRFC2832LimitLocalPart (0.02s)
=== RUN   TestRFC2821LimitPath
--- PASS: TestRFC2821LimitPath (0.03s)
=== RUN   TestRFC2821LimitDomain
--- PASS: TestRFC2821LimitDomain (0.02s)
=== RUN   TestMailFromCmd
--- PASS: TestMailFromCmd (0.05s)
=== RUN   TestHeloEhlo
--- PASS: TestHeloEhlo (0.02s)
=== RUN   TestNestedMailCmd
--- PASS: TestNestedMailCmd (0.02s)
=== RUN   TestCommandLineMaxLength
--- PASS: TestCommandLineMaxLength (0.02s)
=== RUN   TestDataMaxLength
--- PASS: TestDataMaxLength (0.02s)
=== RUN   TestDataCommand
--- PASS: TestDataCommand (0.02s)
=== RUN   TestFuzz86f25b86b09897aed8f6c2aa5b5ee1557358a6de
--- PASS: TestFuzz86f25b86b09897aed8f6c2aa5b5ee1557358a6de (0.02s)
=== RUN   TestFuzz21c56f89989d19c3bbbd81b288b2dae9e6dd2150
--- PASS: TestFuzz21c56f89989d19c3bbbd81b288b2dae9e6dd2150 (0.01s)
PASS
ok      github.com/flashmob/go-guerrilla/tests  1.903s
go test -v ./cmd/guerrillad
vendor/github.com/gomodule/redigo/redis/pool.go:28:2: use of internal package github.com/flashmob/go-guerrilla/vendor/github.com/garyburd/redigo/internal not allowed
Makefile:32: recipe for target 'test' failed
make: *** [test] Error 1```
sajan45 commented 5 years ago

@flashmob yes, I was using it as a package. Don't have that repo in Github so can't show any code to you. But I suspected I was doing something wrong as I was just playing with Golang, it did not feel like an issue with this package, so I closed the issue. And as @artpar experiencing, my issue was in linode instance. And the link provided by @artpar is to a wrong repo (I have removed it from Github now, it's not active too), as I mentioned, that project which was using this package is not in Github.

sajan45 commented 5 years ago

@artpar Which OS you are using? Are you sure it's not the firewall? I think I had to completely disable iptables and then FirewallD (Centos 7) or allow all in UFW (ubuntu) to test a connection and It was FirewallD which was blocking requests. Not sure if this happened when I was trying this package. This is obviously dangerous but at least will rule out a suspect. I don't have much experience with system tools like iptables so I had to do this.

artpar commented 5 years ago

This probably seems like something wrong from my end and not a go-guerrilla issue since I was able to get a super simple independent server working:

package main

import (
        "github.com/flashmob/go-guerrilla"
        "fmt"
       )

func main() {

    d := guerrilla.Daemon{}
    err := d.Start()

         if err == nil {
             fmt.Println("Server Started!")
         }

for {

}

}

OS: From scratch docker image, so no OS

artpar commented 5 years ago

So definitely something related to the docker image.

I am able to connect if I run the executable without docker.

artpar commented 5 years ago

Issue resolved by changing listen interface to 0.0.0.0 instead of 127.0.0.1 earlier.

Thanks