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

Avoid using 100% when using file backend #153

Merged
merged 1 commit into from
Feb 13, 2021

Conversation

PierreF
Copy link
Contributor

@PierreF PierreF commented Feb 13, 2021

The signal watched had a select{} with default clause inside a for{} loop. This cause the default clause to be executed in loop as fast as possible and use 100% CPU.

The following small code show the issue:

package main

import (
	"log"
	"os"
	"time"

	bes "github.com/iegomez/mosquitto-go-auth/backends"
	"github.com/sirupsen/logrus"
)

func main() {
	backend, err := bes.NewFiles(map[string]string{"password_path": "/dev/null"}, logrus.DebugLevel, nil)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("See me (PID = %d) using 100%% CPU :)", os.Getpid())
	time.Sleep(time.Minute)
        backend.Halt()
}

Using top, you will see that without this PR, the process will use 100% CPU.

@iegomez
Copy link
Owner

iegomez commented Feb 13, 2021

Removing the default clause solves it? I thought having a NO-OP default was the same as having none. TIL.

@iegomez
Copy link
Owner

iegomez commented Feb 13, 2021

BTW, @PierreF, now you are a a collaborator, are you able to merge by yourself after approval?

@PierreF PierreF merged commit 9321be9 into iegomez:master Feb 13, 2021
@PierreF
Copy link
Contributor Author

PierreF commented Feb 13, 2021

Looks like I do :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants