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

High CPU Usage and Handlers not being triggered. #1

Open
Baa14453 opened this issue Nov 26, 2021 · 4 comments
Open

High CPU Usage and Handlers not being triggered. #1

Baa14453 opened this issue Nov 26, 2021 · 4 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Baa14453
Copy link

Hi, thanks for making this it looks really good and I'd love to use it but I'm running into some trouble
When I open a session my CPU usage on a single core jumps to 100%,

Also I have some handlers but only the very first date event is triggered none of the others seem to be working, this is my code:

package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"

	"github.com/ropenttd/gopenttd/pkg/admin"
	"github.com/ropenttd/gopenttd/pkg/util"
)

func main() {
	sess, err := admin.New("127.0.0.1", 3977, "admin123")
	if err != nil {
		panic(err)
	}
	err = sess.Open()
	if err != nil {
		panic(err)
	}

	sess.AddHandler(clientJoin)
	sess.AddHandler(getDate)
	sess.AddHandler(onMessage)

	// Wait here until CTRL-C or other term signal is received.
	fmt.Println("Bot is now running.  Press CTRL-C to exit.")
	sc := make(chan os.Signal, 1)
	signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
	<-sc

}

func getDate(sess *admin.Session, d *admin.Date) {
	fmt.Println(util.DateFormat(d.CurrentDate))
}

func clientJoin(sess *admin.Session, d *admin.ClientJoin) {
	fmt.Println("Meow")
}

func onMessage(sess *admin.Session, d *admin.Chat) {
	fmt.Println("Message sent")
}

It's meant to print Meow or Message Sent when someone sends a chat message or joins the server, it should also print the current date whenever it's triggered but the only output is a single Current Date:

Starting: /home/baa/go/bin/dlv-dap dap --check-go-version=false --listen=127.0.0.1:42275 --log-dest=3 from /home/baa/Documents/Dev/OpenTTD-Discord-Bot
DAP server listening at: 127.0.0.1:42275
Type 'dlv help' for list of commands.
Bot is now running.  Press CTRL-C to exit.
1991-01-05 00:00:00 +0000 UTC
@duckfullstop
Copy link
Contributor

My apologies for the delay; I did get your email

To be honest, I hadn't fully finished writing this when some major life stuff happened and I had to drop basically everything on the floor for a while - so a fair amount of stuff is probably fairly buggy or missing entirely. That being said, I'll try to find a spare afternoon to fire up my IDE and track down the cause of the leaks, as well as the handlers not firing (iirc this was something i was working on).

If you manage to find them yourself, feel free to fire a PR and I'll review it ASAP.

@duckfullstop duckfullstop added bug Something isn't working good first issue Good for newcomers labels Dec 1, 2021
@duckfullstop duckfullstop self-assigned this Dec 1, 2021
@Baa14453
Copy link
Author

Baa14453 commented Dec 1, 2021

It's good to see you're around :D
We are temporarily patching bugs here and will make a Pull in the future

@Baa14453
Copy link
Author

Baa14453 commented Dec 1, 2021

And regarding the Handlers, I found that for some of them I needed to set them to UpdateFrequencyAutomatically by default, and after that they fired ok. The thing I'm writing is here.

duckfullstop added a commit that referenced this issue Dec 3, 2021
Still arguably broken, but this might get some people in #1 out of trouble.

Signed-off-by: duck <[email protected]>
@duckfullstop
Copy link
Contributor

I've just pushed my latest head revision that I had on my laptop, can you test against
ccf1a51? It's untested due to a lack of a test setup at present, but it might be a bit more working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants