Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from cmd/server does not work as expected #71

Open
ashumkin opened this issue Aug 1, 2024 · 2 comments
Open

Example from cmd/server does not work as expected #71

ashumkin opened this issue Aug 1, 2024 · 2 comments

Comments

@ashumkin
Copy link

ashumkin commented Aug 1, 2024

I run

go run  cmd/server/main.go

server starts, outputs

Running...

Then I run

curl 'localhost:8081/set?key=a&value=1'

server outputs

Set: [a]1

then I run

curl 'localhost:8081/cache?key=a'

server outputs

Fetching value for key 'a'

curl hangs for a while then outputs

context deadline exceeded

I expect server will output the value 1 set for the key a

@ashumkin
Copy link
Author

ashumkin commented Aug 1, 2024

Also, the same code (with removed expiration time on the line 27 ) works well with the original golang/groupcache package

$ curl 'localhost:8081/set?key=a&value=1' -i
HTTP/1.1 200 OK
Date: Thu, 01 Aug 2024 16:46:31 GMT
Content-Length: 0

$ curl 'localhost:8081/cache?key=a' -i
HTTP/1.1 200 OK
Date: Thu, 01 Aug 2024 16:46:33 GMT
Content-Length: 2
Content-Type: text/plain; charset=utf-8

1

@udhos
Copy link
Contributor

udhos commented Dec 15, 2024

Problem is:

addr defaults to :8080:

https://github.com/mailgun/groupcache/blob/master/cmd/server/main.go#L38

addr := flag.String("addr", ":8080", "server address")

Then this line renders current URL as http://:8080:

https://github.com/mailgun/groupcache/blob/master/cmd/server/main.go#L44

pool := groupcache.NewHTTPPoolOpts(fmt.Sprintf("http://%s", *addr), &groupcache.HTTPPoolOptions{})

And the peers var should include the (corrected) URL that is passed to NewHTTPPoolOpts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants