golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.29k stars 17.7k forks source link

x/playground: program continues running after timeout #56543

Open orizerah opened 2 years ago

orizerah commented 2 years ago

What is the URL of the page with the issue?

https://go.dev/play/p/nFK61FSRjMa

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.134 Safari/537.36 Edg/103.0.1264.71

Screenshot

image

What did you do?

I was playing with channels, trying to understand when a channel is blocked, and I managed to make the program to continue working even after getting the timeout prompt. Here's a snippet of the code:

// You can edit this code!
// Click here and start typing.
package main

import (
    "fmt"
    "sync"
    "time"
)

func w(c chan<- int) {
    for {
        time.Sleep(time.Second * 1)
        fmt.Println("Sending number 1")
        c <- 1
    }
}

func main() {
    var wg sync.WaitGroup
    c := make(chan int)
    go func(wg *sync.WaitGroup, c chan<- int) {
        defer wg.Done()
        w(c)
    }(&wg, c)

    for r := range c {
        fmt.Printf("Got Number %d", r)
    }
}

What did you expect to see?

I expected the program to stop after getting timeout, and in general, for something to crash after the program continued

What did you see instead?

The program runs forever

seankhliao commented 2 years ago

cc @toothrot

bcmills commented 2 years ago

The program doesn't run forever. It is using the faketime implementation, so it buffers up to some amount of timestamped output and then plays that back. The amount of output in the buffer may cover a very long wall-time interval, even though the amount of time to simulate that interval in the playground was actually much shorter.