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

Deadlock when using fsnotify on Windows #54

Open
rubenhazelaar opened this issue Jul 2, 2015 · 6 comments
Open

Deadlock when using fsnotify on Windows #54

rubenhazelaar opened this issue Jul 2, 2015 · 6 comments
Labels

Comments

@rubenhazelaar
Copy link

Hi, I'm new to Go and have written a very simple program to watch some logs (which rotate). However although the program runs fine for some time, eventually it deadlocks with the following message:

fatal error: all goroutines are asleep - deadlock! 

The code I'm using looks like this:

t, err := tail.TailFile("path/to/some/log", tail.Config{
    Follow: true,
    ReOpen: true})
if err != nil {
    log.Fatal(err)
}

for line := range t.Lines {
    // Some action based on a log line
}

I can provide a stacktrace if necessary

BTW: I'm on Windows.

@srid
Copy link
Contributor

srid commented Jul 3, 2015

What is the full code (the .go file)? Example program can be found here: https://github.com/ActiveState/tail/blob/master/cmd/gotail/gotail.go

@srid srid changed the title Tail results in deadlock Deadlock for a simple tail program Jul 3, 2015
@rubenhazelaar
Copy link
Author

Here the full code, I think it has something to do with fsnotify for windows. With poll = true the problem does not occur. As you see it is much simpeler than your example, I think I implemented it correctly. Below the code also the stacktrace for the go routines.

package main

import (
    "github.com/ActiveState/tail"
    "log"
    "regexp"
)

func main() {
    t, err := tail.TailFile("path/to/log/file", tail.Config{
        Follow: true,
        ReOpen: true,
        Poll: true, // With poll = true appended the problem does NOT occur, so suspect it has something to do with fsnotify
    })
    if err != nil {
        log.Fatal(err)
    }

    r, err := regexp.Compile(`regex`)
    if err != nil {
        log.Println("There is problem with the regexp.")
        return
    }

    for line := range t.Lines {
        if r.MatchString(line.Text) == true {
            // action
        }
    }
}

Stacktrace:

fatal error: all goroutines are asleep - deadlock!

goroutine 1 [chan receive]:
main.main()
        src/user/main.go
dcwatcher/main.go:26 +0x2e5

goroutine 5 [select]:
github.com/ActiveState/tail.(*Tail).waitForChanges(0xc08204e000, 0x0, 0x0)
        src/github.com/ActiveState/tail/tail.g
o:298 +0x922
github.com/ActiveState/tail.(*Tail).tailFileSync(0xc08204e000)
        src/github.com/ActiveState/tail/tail.g
o:265 +0xa5f
created by github.com/ActiveState/tail.TailFile
        src/github.com/ActiveState/tail/tail.g
o:113 +0x471

goroutine 12 [chan send, locked to thread]:
gopkg.in/fsnotify%2ev0.(*Watcher).readEvents(0xc082086f00)
        src/gopkg.in/fsnotify.v0/fsnotify_wind
ows.go:479 +0xbfe
created by gopkg.in/fsnotify%2ev0.NewWatcher
        src/gopkg.in/fsnotify.v0/fsnotify_wind
ows.go:148 +0x452

goroutine 13 [chan receive]:
gopkg.in/fsnotify%2ev0.(*Watcher).purgeEvents(0xc082086f00)
        src/gopkg.in/fsnotify.v0/fsnotify.go:2
1 +0x5c
created by gopkg.in/fsnotify%2ev0.NewWatcher
        src/gopkg.in/fsnotify.v0/fsnotify_wind
ows.go:149 +0x46c

goroutine 14 [select]:
github.com/ActiveState/tail/watch.func┬À001()
        src/github.com/ActiveState/tail/watch/
inotify.go:88 +0x502
created by github.com/ActiveState/tail/watch.(*InotifyFileWatcher).ChangeEvents
        src/github.com/ActiveState/tail/watch/
inotify.go:125 +0x54a

@srid srid changed the title Deadlock for a simple tail program Deadlock when using fsnotify on Windows Jul 3, 2015
@srid srid removed the question label Jul 3, 2015
@Nino-K
Copy link
Contributor

Nino-K commented Apr 28, 2016

Hi @rubenhazelaar, I have upgraded the version of fsnotify from v0 to v1. Have you tried the newer version of tail, to see if you are still seeing this issue?

@mitchellh
Copy link

I'm not seeing a deadlock error but I can confirm that with a log file that is not frequently updated (maybe once per second) I am seeing tail stop sending lines after a certain period of time when using Poll: false. By setting poll to true, everything works fine.

Note that this is on Windows. On OS X everything appears to work fine with poll false.

@Nino-K
Copy link
Contributor

Nino-K commented May 20, 2016

Hi @mitchellh, thanks for pointing it out. Can you confirm if you have tried this on the latest master, with fsnotify v1?

It is a known issue that I'm currently looking into it. I was hoping updating fsnotify to v1 would have rectified it as it originally appeared to be from fsnotify.

@sunshine69
Copy link

This seems not to be resolved yet. I have just hit the same issue and currently watching the poll options to see if it is happy.

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

No branches or pull requests

5 participants