同时开启http,和https,
app.conf: httpport = 8080 HTTPSPort = 8888 enablehttp = true EnableHTTPS = true EnableHttpTLS = true
运行: bee run
就出错: ListenAndServe: listen tcp :8888: bind: address already in use
单独运行http,或https都没问题,同时开htt和https就报错
同时开启http,和https,
app.conf: httpport = 8080 HTTPSPort = 8888 enablehttp = true EnableHTTPS = true EnableHttpTLS = true
运行: bee run
就出错: ListenAndServe: listen tcp :8888: bind: address already in use
单独运行http,或https都没问题,同时开htt和https就报错
可以,你的错误提示你的8888端口已经被占用了啊
mac 一直无法同时启动,linux下一定几率无法同时启动,不知为何,很明确不是其他程序端口占用了。
我想问下, 你这个问题解决了吗? @ywolf
@ywolf 提示bind: address already in use
的话是指端口已经占用。可以先用指令检查一下。如果还启动失败,建议把log贴上来分析
可以很确定的说, 端口肯定没被使用. 其次在哪里可以看更详细的log?
问题初步锁定在beego的app.go文件中
if BConfig.Listen.EnableHTTPS { go func() { time.Sleep(1000 * time.Microsecond) if BConfig.Listen.HTTPSPort != 0 { app.Server.Addr = fmt.Sprintf("%s:%d", BConfig.Listen.HTTPSAddr, BConfig.Listen.HTTPSPort) } else if BConfig.Listen.EnableHTTP { BeeLogger.Info("Start https server error, confict with http.Please reset https port") return } logs.Info("https server Running on https://%s", app.Server.Addr) if err := app.Server.ListenAndServeTLS(BConfig.Listen.HTTPSCertFile, BConfig.Listen.HTTPSKeyFile); err != nil { logs.Critical("ListenAndServeTLS: ", err) time.Sleep(100 * time.Microsecond) endRunning <- true } }() }
这里有一个睡眠时间, 默认为20Millisecond
这个时间太短了, 我放到200Millisecond的时候, 报错频率明显下降
我把时间放到 1000* Millisecond,报错频率为0了, (测试样本不足, 大概重启了20遍, 没有出现报错)
@xuange306 https://github.com/astaxie/beego/pull/3102 我们在使用的时候发现了这个问题,通过这个方式可以修复,最新官方版本不知道已经修了没。