Fix releasing page mutex during template execution
This commit is contained in:
parent
7f667e2d1c
commit
d4b1d240b9
1 changed files with 10 additions and 6 deletions
|
|
@ -92,9 +92,6 @@ func newApplication(config *config) (*application, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *page) updateOutdatedWidgets() {
|
func (p *page) updateOutdatedWidgets() {
|
||||||
p.mu.Lock()
|
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
@ -168,10 +165,17 @@ func (a *application) handlePageContentRequest(w http.ResponseWriter, r *http.Re
|
||||||
Page: page,
|
Page: page,
|
||||||
}
|
}
|
||||||
|
|
||||||
page.updateOutdatedWidgets()
|
var err error
|
||||||
|
|
||||||
var responseBytes bytes.Buffer
|
var responseBytes bytes.Buffer
|
||||||
err := pageContentTemplate.Execute(&responseBytes, pageData)
|
|
||||||
|
func() {
|
||||||
|
page.mu.Lock()
|
||||||
|
defer page.mu.Unlock()
|
||||||
|
|
||||||
|
page.updateOutdatedWidgets()
|
||||||
|
err = pageContentTemplate.Execute(&responseBytes, pageData)
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
w.Write([]byte(err.Error()))
|
w.Write([]byte(err.Error()))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue