MM-43775: Use conn.NetConn() to get TCP conn from tls.Conn (#20180)
We use the new API in Go 1.18 to set TCP_NO_DELAY for tls connections as well. https://mattermost.atlassian.net/browse/MM-43775 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a6d8e45297
Коммит
231db2df1e
@@ -5,6 +5,7 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -168,10 +169,18 @@ func (a *App) NewWebConn(cfg *WebConnConfig) *WebConn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Disable TCP_NO_DELAY for higher throughput
|
// Disable TCP_NO_DELAY for higher throughput
|
||||||
// Unfortunately, it doesn't work for tls.Conn,
|
var tcpConn *net.TCPConn
|
||||||
// and currently, the API doesn't expose the underlying TCP conn.
|
switch conn := cfg.WebSocket.UnderlyingConn().(type) {
|
||||||
tcpConn, ok := cfg.WebSocket.UnderlyingConn().(*net.TCPConn)
|
case *net.TCPConn:
|
||||||
if ok {
|
tcpConn = conn
|
||||||
|
case *tls.Conn:
|
||||||
|
newConn, ok := conn.NetConn().(*net.TCPConn)
|
||||||
|
if ok {
|
||||||
|
tcpConn = newConn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tcpConn != nil {
|
||||||
err := tcpConn.SetNoDelay(false)
|
err := tcpConn.SetNoDelay(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
mlog.Warn("Error in setting NoDelay socket opts", mlog.Err(err))
|
mlog.Warn("Error in setting NoDelay socket opts", mlog.Err(err))
|
||||||
@@ -334,7 +343,9 @@ func (wc *WebConn) readPump() {
|
|||||||
wc.WebSocket.SetReadLimit(model.SocketMaxMessageSizeKb)
|
wc.WebSocket.SetReadLimit(model.SocketMaxMessageSizeKb)
|
||||||
wc.WebSocket.SetReadDeadline(time.Now().Add(pongWaitTime))
|
wc.WebSocket.SetReadDeadline(time.Now().Add(pongWaitTime))
|
||||||
wc.WebSocket.SetPongHandler(func(string) error {
|
wc.WebSocket.SetPongHandler(func(string) error {
|
||||||
wc.WebSocket.SetReadDeadline(time.Now().Add(pongWaitTime))
|
if err := wc.WebSocket.SetReadDeadline(time.Now().Add(pongWaitTime)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if wc.IsAuthenticated() {
|
if wc.IsAuthenticated() {
|
||||||
wc.App.Srv().Go(func() {
|
wc.App.Srv().Go(func() {
|
||||||
wc.App.SetStatusAwayIfNeeded(wc.UserId, false)
|
wc.App.SetStatusAwayIfNeeded(wc.UserId, false)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user