Skip to content

Commit

Permalink
fixed: multiple concurrent map writes exception during heavy load
Browse files Browse the repository at this point in the history
  • Loading branch information
kgretzky committed Oct 22, 2019
1 parent 5afb6d9 commit 99f83c3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.3.3
- Fixed: Multiple concurrent map writes when whitelisting IPs during heavy loads.

2.3.2
- ACMEv2 support added to comply with LetsEncrypt requirements.
- Fixed session cookie output to support EditThisCookie on the latest Chrome version.
Expand Down
2 changes: 1 addition & 1 deletion core/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

const (
VERSION = "2.3.2"
VERSION = "2.3.3"
)

func putAsciiArt(s string) {
Expand Down
11 changes: 11 additions & 0 deletions core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strconv"
"strings"
"sync"
"time"

"github.com/elazarl/goproxy"
Expand Down Expand Up @@ -61,6 +62,7 @@ type HttpProxy struct {
ip_whitelist map[string]int64
ip_sids map[string]string
auto_filter_mimes []string
ip_mtx sync.Mutex
}

type ProxySession struct {
Expand Down Expand Up @@ -1058,12 +1060,18 @@ func (p *HttpProxy) deleteRequestCookie(name string, req *http.Request) {
}

func (p *HttpProxy) whitelistIP(ip_addr string, sid string) {
p.ip_mtx.Lock()
defer p.ip_mtx.Unlock()

log.Debug("whitelistIP: %s %s", ip_addr, sid)
p.ip_whitelist[ip_addr] = time.Now().Add(15 * time.Second).Unix()
p.ip_sids[ip_addr] = sid
}

func (p *HttpProxy) isWhitelistedIP(ip_addr string) bool {
p.ip_mtx.Lock()
defer p.ip_mtx.Unlock()

log.Debug("isWhitelistIP: %s", ip_addr)
ct := time.Now()
if ip_t, ok := p.ip_whitelist[ip_addr]; ok {
Expand All @@ -1074,6 +1082,9 @@ func (p *HttpProxy) isWhitelistedIP(ip_addr string) bool {
}

func (p *HttpProxy) getSessionIdByIP(ip_addr string) (string, bool) {
p.ip_mtx.Lock()
defer p.ip_mtx.Unlock()

sid, ok := p.ip_sids[ip_addr]
return sid, ok
}
Expand Down

0 comments on commit 99f83c3

Please sign in to comment.