mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
@ -138,5 +138,7 @@ func getFreePort() (port int, err error) {
|
||||
}
|
||||
|
||||
defer listener.Close()
|
||||
// This is always a *net.TCPAddr.
|
||||
// nolint:forcetypeassert
|
||||
return listener.Addr().(*net.TCPAddr).Port, nil
|
||||
}
|
||||
|
@ -72,6 +72,9 @@ func (p *pgPubsub) Subscribe(event string, listener Listener) (cancel func(), er
|
||||
}
|
||||
|
||||
func (p *pgPubsub) Publish(event string, message []byte) error {
|
||||
// This is safe because we are calling pq.QuoteLiteral. pg_notify doesn't
|
||||
// support the first parameter being a prepared statement.
|
||||
//nolint:gosec
|
||||
_, err := p.db.ExecContext(context.Background(), `select pg_notify(`+pq.QuoteLiteral(event)+`, $1)`, message)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("exec: %w", err)
|
||||
|
@ -138,7 +138,9 @@ func (api *api) provisionerJobLogs(rw http.ResponseWriter, r *http.Request, job
|
||||
// See: https://canjs.com/doc/can-ndjson-stream.html
|
||||
rw.Header().Set("Content-Type", "application/stream+json")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
rw.(http.Flusher).Flush()
|
||||
if flusher, ok := rw.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
|
||||
// The Go stdlib JSON encoder appends a newline character after message write.
|
||||
encoder := json.NewEncoder(rw)
|
||||
@ -161,7 +163,9 @@ func (api *api) provisionerJobLogs(rw http.ResponseWriter, r *http.Request, job
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rw.(http.Flusher).Flush()
|
||||
if flusher, ok := rw.(http.Flusher); ok {
|
||||
flusher.Flush()
|
||||
}
|
||||
case <-ticker.C:
|
||||
job, err := api.Database.GetProvisionerJobByID(r.Context(), job.ID)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user