Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debugstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func DebugState() FrankenPHPDebugState {
func threadDebugState(thread *phpThread) ThreadDebugState {
return ThreadDebugState{
Index: thread.threadIndex,
Name: thread.handler.name(),
Name: thread.name(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also fixes a rare race condition with the debug state that I noticed during testing.

State: thread.state.name(),
IsWaiting: thread.state.isInWaitingState(),
IsBusy: !thread.state.isInWaitingState(),
Expand Down
5 changes: 3 additions & 2 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,12 @@ func TestFailingWorker(t *testing.T) {
}

func TestEnv(t *testing.T) {
testEnv(t, &testOptions{nbParallelRequests:1})
testEnv(t, &testOptions{nbParallelRequests: 1})
}
func TestEnvWorker(t *testing.T) {
testEnv(t, &testOptions{nbParallelRequests:1, workerScript: "env/test-env.php"})
testEnv(t, &testOptions{nbParallelRequests: 1, workerScript: "env/test-env.php"})
}

// testEnv cannot be run in parallel due to https://github.com/golang/go/issues/63567
func testEnv(t *testing.T, opts *testOptions) {
assert.NoError(t, os.Setenv("EMPTY", ""))
Expand Down
2 changes: 1 addition & 1 deletion internal/watcher/watch_pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
type watchPattern struct {
dir string
patterns []string
trigger chan struct{}
trigger chan string
failureCount int
}

Expand Down
6 changes: 4 additions & 2 deletions internal/watcher/watch_pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ func TestInValidExtendedPatterns(t *testing.T) {
func TestAnAssociatedEventTriggersTheWatcher(t *testing.T) {
watchPattern, err := parseFilePattern("/**/*.php")
assert.NoError(t, err)
watchPattern.trigger = make(chan struct{})
watchPattern.trigger = make(chan string)

go handleWatcherEvent(watchPattern, "/path/temorary_file", "/path/file.php", 0, 0)

var path string
select {
case <-watchPattern.trigger:
case path = <-watchPattern.trigger:
assert.Equal(t, "/path/file.php", path, "should be associated file path")
case <-time.After(2 * time.Second):
assert.Fail(t, "associated watchPattern did not trigger after 2s")
}
Expand Down
15 changes: 8 additions & 7 deletions internal/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
type watcher struct {
sessions []C.uintptr_t
callback func()
trigger chan struct{}
trigger chan string
stop chan struct{}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func retryWatching(watchPattern *watchPattern) {
}

func (w *watcher) startWatching(filePatterns []string) error {
w.trigger = make(chan struct{})
w.trigger = make(chan string)
w.stop = make(chan struct{})
w.sessions = make([]C.uintptr_t, len(filePatterns))
watchPatterns, err := parseFilePatterns(filePatterns)
Expand Down Expand Up @@ -166,37 +166,38 @@ func handleWatcherEvent(watchPattern *watchPattern, path string, associatedPath
}

if watchPattern.allowReload(path, eventType, pathType) {
watchPattern.trigger <- struct{}{}
watchPattern.trigger <- path
return
}

// some editors create temporary files and never actually modify the original file
// so we need to also check the associated path of an event
// see https://github.com/dunglas/frankenphp/issues/1375
if associatedPath != "" && watchPattern.allowReload(associatedPath, eventType, pathType) {
watchPattern.trigger <- struct{}{}
watchPattern.trigger <- associatedPath
}
}

func listenForFileEvents(triggerWatcher chan struct{}, stopWatcher chan struct{}) {
func listenForFileEvents(triggerWatcher chan string, stopWatcher chan struct{}) {
timer := time.NewTimer(debounceDuration)
timer.Stop()
lastChangedFile := ""
defer timer.Stop()
for {
select {
case <-stopWatcher:
break
case <-triggerWatcher:
case lastChangedFile = <-triggerWatcher:
timer.Reset(debounceDuration)
case <-timer.C:
timer.Stop()
logger.Info("filesystem change detected", zap.String("file", lastChangedFile))
scheduleReload()
}
}
}

func scheduleReload() {
logger.Info("filesystem change detected")
reloadWaitGroup.Add(1)
activeWatcher.callback()
reloadWaitGroup.Done()
Expand Down
Loading