1
0
mirror of https://github.com/golang/go synced 2024-11-05 20:36:10 -07:00

Revert "godoc: init corpus in a separate goroutine in http mode"

This reverts commit f86b507a7e.

Reason for revert: broke tests in tools repo

Change-Id: Id7e5d8e050896b6f5fedaee705be8a5f9adf4bf3
Reviewed-on: https://go-review.googlesource.com/93115
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Andrew Bonventre 2018-02-09 16:58:40 +00:00
parent 66487607e2
commit 70252dea49
3 changed files with 4 additions and 36 deletions

View File

@ -153,13 +153,6 @@ func handleURLFlag() {
log.Fatalf("too many redirects") log.Fatalf("too many redirects")
} }
func initCorpus(corpus *godoc.Corpus) {
err := corpus.Init()
if err != nil {
log.Fatal(err)
}
}
func main() { func main() {
flag.Usage = usage flag.Usage = usage
flag.Parse() flag.Parse()
@ -238,10 +231,8 @@ func main() {
corpus.IndexEnabled = true corpus.IndexEnabled = true
} }
if *writeIndex || httpMode || *urlFlag != "" { if *writeIndex || httpMode || *urlFlag != "" {
if httpMode { if err := corpus.Init(); err != nil {
go initCorpus(corpus) log.Fatal(err)
} else {
initCorpus(corpus)
} }
} }
@ -332,9 +323,6 @@ func main() {
} }
// Start http server. // Start http server.
if *verbose {
log.Println("starting http server")
}
if err := http.ListenAndServe(*httpAddr, handler); err != nil { if err := http.ListenAndServe(*httpAddr, handler); err != nil {
log.Fatalf("ListenAndServe %s: %v", *httpAddr, err) log.Fatalf("ListenAndServe %s: %v", *httpAddr, err)
} }

View File

@ -7,7 +7,6 @@ package godoc
import ( import (
"errors" "errors"
pathpkg "path" pathpkg "path"
"sync"
"time" "time"
"golang.org/x/tools/godoc/analysis" "golang.org/x/tools/godoc/analysis"
@ -104,10 +103,6 @@ type Corpus struct {
// Analysis is the result of type and pointer analysis. // Analysis is the result of type and pointer analysis.
Analysis analysis.Result Analysis analysis.Result
// flag to check whether a corpus is initialized or not
initMu sync.RWMutex
initDone bool
} }
// NewCorpus returns a new Corpus from a filesystem. // NewCorpus returns a new Corpus from a filesystem.
@ -141,15 +136,13 @@ func (c *Corpus) FSModifiedTime() time.Time {
// Init initializes Corpus, once options on Corpus are set. // Init initializes Corpus, once options on Corpus are set.
// It must be called before any subsequent method calls. // It must be called before any subsequent method calls.
func (c *Corpus) Init() error { func (c *Corpus) Init() error {
// TODO(bradfitz): do this in a goroutine because newDirectory might block for a long time?
// It used to be sometimes done in a goroutine before, at least in HTTP server mode.
if err := c.initFSTree(); err != nil { if err := c.initFSTree(); err != nil {
return err return err
} }
c.updateMetadata() c.updateMetadata()
go c.refreshMetadataLoop() go c.refreshMetadataLoop()
c.initMu.Lock()
c.initDone = true
c.initMu.Unlock()
return nil return nil
} }

View File

@ -7,7 +7,6 @@ package godoc
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"go/ast" "go/ast"
"go/build" "go/build"
@ -249,12 +248,6 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
relpath := pathpkg.Clean(r.URL.Path[len(h.stripPrefix)+1:]) relpath := pathpkg.Clean(r.URL.Path[len(h.stripPrefix)+1:])
if !h.corpusInitialized() {
h.p.ServeError(w, r, relpath, errors.New("Scan is not yet complete. Please retry after a few moments"))
return
}
abspath := pathpkg.Join(h.fsRoot, relpath) abspath := pathpkg.Join(h.fsRoot, relpath)
mode := h.p.GetPageInfoMode(r) mode := h.p.GetPageInfoMode(r)
if relpath == builtinPkgPath { if relpath == builtinPkgPath {
@ -329,12 +322,6 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}) })
} }
func (h *handlerServer) corpusInitialized() bool {
h.c.initMu.RLock()
defer h.c.initMu.RUnlock()
return h.c.initDone
}
type PageInfoMode uint type PageInfoMode uint
const ( const (