Comments (4)
Could you please add a full stack trace of the panic you’re running into?
from go-any-proxy.
package main
import (
"fmt"
"time"
"gitea.com/lunny/log"
)
type cacheEntry struct {
hostname string
expires time.Time
}
type reverseLookupCache struct {
hostnames map[string]*cacheEntry
keys []string
next int
}
func NewReverseLookupCache() *reverseLookupCache {
return &reverseLookupCache{
hostnames: make(map[string]*cacheEntry),
keys: make([]string, 65536),
}
}
func (c *reverseLookupCache) lookup(ipv4 string) string {
hit := c.hostnames[ipv4]
if hit != nil {
if hit.expires.After(time.Now()) {
log.Debugf("lookup(): CACHE_HIT")
return hit.hostname
} else {
log.Debugf("lookup(): CACHE_EXPIRED")
delete(c.hostnames, ipv4)
}
} else {
log.Debugf("lookup(): CACHE_MISS")
}
return ""
}
func (c *reverseLookupCache) store(ipv4, hostname string) {
delete(c.hostnames, c.keys[c.next])
c.keys[c.next] = ipv4
c.next = (c.next + 1) & 65535
c.hostnames[ipv4] = &cacheEntry{hostname: hostname, expires: time.Now().Add(time.Hour)}
}
var gReverseLookupCache *reverseLookupCache
func main() {
gReverseLookupCache = NewReverseLookupCache()
for i := 0; i < 10; i++ {
go func() {
ipv4 := fmt.Sprintf("test-%d", i)
hostname := gReverseLookupCache.lookup(ipv4)
if hostname != "" {
ipv4 = hostname
} else {
val := fmt.Sprintf("val-%d", i)
gReverseLookupCache.store(ipv4, val)
}
}()
}
}
from go-any-proxy.
go: finding gitea.com/lunny/log latest
fatal error: concurrent map read and map write
goroutine 12 [running]:
runtime.throw(0x4cf674, 0x21)
>---/data/opt/go/src/runtime/panic.go:617 +0x72 fp=0xc000031eb0 sp=0xc000031e80 pc=0x428f92
runtime.mapaccess1_faststr(0x4ae680, 0xc0000721b0, 0xc000182090, 0x7, 0x7)
>---/data/opt/go/src/runtime/map_faststr.go:21 +0x469 fp=0xc000031f20 sp=0xc000031eb0 pc=0x40ffe9
main.(*reverseLookupCache).lookup(0xc0000721e0, 0xc000182090, 0x7, 0x1, 0x1)
>---/data/app/golang/src/test.go:27 +0x52 fp=0xc000031f70 sp=0xc000031f20 pc=0x494f22
main.main.func1(0xc000014110)
>---/data/app/golang/src/test.go:56 +0xb3 fp=0xc000031fd8 sp=0xc000031f70 pc=0x4954e3
runtime.goexit()
>---/data/opt/go/src/runtime/asm_amd64.s:1337 +0x1 fp=0xc000031fe0 sp=0xc000031fd8 pc=0x452181
created by main.main
>---/data/app/golang/src/test.go:54 +0xe8
goroutine 1 [runnable]:
runtime.gopark(0x0, 0x0, 0xc000021008, 0x1)
>---/data/opt/go/src/runtime/proc.go:284 +0x13d
runtime.main()
>---/data/opt/go/src/runtime/proc.go:219 +0x287
runtime.goexit()
>---/data/opt/go/src/runtime/asm_amd64.s:1337 +0x1
goroutine 8 [runnable]:
fmt.Sprintf(0x4cce92, 0x14, 0x0, 0x0, 0x0, 0xc0001b4000, 0x0)
>---/data/opt/go/src/fmt/print.go:215 +0x92
gitea.com/lunny/log.Debugf(0x4cce92, 0x14, 0x0, 0x0, 0x0)
>---/data/app/golang/pkg/mod/gitea.com/lunny/[email protected]/logext.go:522 +0x57
main.(*reverseLookupCache).lookup(0xc0000721e0, 0xc000192010, 0x7, 0x1, 0x1)
>---/data/app/golang/src/test.go:37 +0x196
main.main.func1(0xc000014110)
>---/data/app/golang/src/test.go:56 +0xb3
created by main.main
>---/data/app/golang/src/test.go:54 +0xe8
from go-any-proxy.
Thanks for reporting that. You are indeed correct, that struct needs to be synchronized. If you have time, could you send in a PR? If not, I'll take care of it this week.
from go-any-proxy.
Related Issues (20)
- Log go version on startup
- Investigate TCP connection repair for HA
- Wrong logic for eth interface in init.d debian script
- Rules engine based on DNS
- I have written a tproxy listener socket, can you add this function to your proxy? HOT 1
- Panic invalid memory address nil pointer de reference HOT 3
- Disconnects from proxy server HOT 4
- MPTCP (Multipath TCP) support/testing HOT 3
- i installed any_proxy ,failed,how to fix it? HOT 2
- Can go-any-proxy Do This? HOT 3
- Release all connections if too many files are opened HOT 7
- Proxy HTTP requests HOT 2
- Failed to proxy HOT 10
- Installation instructions fail on impish HOT 4
- Use any-proxy as SMTP/IMAP forwarder HOT 1
- CONNECT always results in: HTTP/1.1 403 URLBlocked HOT 4
- TESTING: close clientConn at various times
- Rules based on SSL certificate HOT 6
- Change net.Dial to net.DialTCP HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-any-proxy.