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

NotifyHandler does not function with compiler inlining enabled. #2

Open
Adam-Ant opened this issue Dec 1, 2017 · 0 comments
Open

Comments

@Adam-Ant
Copy link

Adam-Ant commented Dec 1, 2017

Hello,
I've been trying to use your library, and the notification handing system in it, but have come up against a strange issue. By default, Go seems to inline the NotifyHandler function, which for some reason breaks it, and so the function specified in it is never called.
I've fixed this locally by adding the compiler directive //go:noinline above the NotifyHandler and NotifyHandlerString functions, but this is probably a hack rather than a long-term fix.

A minimal program to re-produce this can be found below:

package main

import (
	"github.com/darfk/ts3"
	"log"
)

func main() {

	notification := make(chan ts3.Notification)

	go processNotify(notification)

	client, err := ts3.NewClient("ts3.example.com:10011")
	if err != nil {
		log.Fatal(err)
	}

	_, err = client.Exec(ts3.Login("gotest", "password"))
	if err != nil {
		log.Fatal(err)
	}

	_, err = client.Exec(ts3.Use(1))
	if err != nil {
		log.Fatal(err)
	}

	response, err := client.Exec(ts3.Command{
		Command: "servernotifyregister",
		Params: map[string][]string{
			"event": []string{"channel"},
			"id":    []string{"1"},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	client.NotifyHandler( func(n ts3.Notification) {
		log.Println(n)
	})

	for {
	}

Build normally, with go build, then move from the root channel on teampseak to another, note no output.
But when built with go build -gcflags '-l', which disables inline optimization, the expected output is given.

Tested on Arch Linux, with go version 1.9.2

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

1 participant