From f605e1138dd798625b78c66c37880b64fa89b2e3 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Sat, 16 Aug 2014 16:52:09 -0400 Subject: [PATCH 1/4] kortschak's fix --- query/gremlin/session.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/query/gremlin/session.go b/query/gremlin/session.go index 8000c17..c178785 100644 --- a/query/gremlin/session.go +++ b/query/gremlin/session.go @@ -111,7 +111,6 @@ func (s *Session) SendResult(r *Result) bool { } func (s *Session) runUnsafe(input interface{}) (otto.Value, error) { - s.kill = make(chan struct{}) defer func() { if r := recover(); r != nil { if r == ErrKillTimeout { @@ -125,9 +124,12 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) { // Use buffered chan to prevent blocking. s.env.Interrupt = make(chan func(), 1) + ready := make(chan struct{}) + s.kill = make(chan struct{}) if s.timeout >= 0 { go func() { time.Sleep(s.timeout) + <-ready close(s.kill) s.envLock.Lock() defer s.envLock.Unlock() @@ -143,6 +145,7 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) { s.envLock.Lock() env := s.env s.envLock.Unlock() + close(ready) return env.Run(input) } From c1ff6ce1aa584a6354fe29793230d3b9556526c8 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Sat, 16 Aug 2014 18:03:05 -0400 Subject: [PATCH 2/4] lock s.kill, send done signal --- query/gremlin/session.go | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/query/gremlin/session.go b/query/gremlin/session.go index c178785..afd77b6 100644 --- a/query/gremlin/session.go +++ b/query/gremlin/session.go @@ -93,8 +93,11 @@ func (s *Session) SendResult(r *Result) bool { if s.limit >= 0 && s.limit == s.count { return false } + s.envLock.Lock() + kill := s.kill + s.envLock.Unlock() select { - case <-s.kill: + case <-kill: return false default: } @@ -125,28 +128,40 @@ func (s *Session) runUnsafe(input interface{}) (otto.Value, error) { s.env.Interrupt = make(chan func(), 1) ready := make(chan struct{}) - s.kill = make(chan struct{}) + done := make(chan struct{}) if s.timeout >= 0 { go func() { time.Sleep(s.timeout) <-ready - close(s.kill) - s.envLock.Lock() - defer s.envLock.Unlock() - if s.env != nil { - s.env.Interrupt <- func() { - panic(ErrKillTimeout) + select { + case <-done: + return + default: + close(s.kill) + s.envLock.Lock() + defer s.envLock.Unlock() + s.kill = nil + if s.env != nil { + s.env.Interrupt <- func() { + panic(ErrKillTimeout) + } + s.env = s.emptyEnv } - s.env = s.emptyEnv + return } }() } s.envLock.Lock() env := s.env + if s.kill == nil { + s.kill = make(chan struct{}) + } s.envLock.Unlock() close(ready) - return env.Run(input) + out, err := env.Run(input) + close(done) + return out, err } func (s *Session) ExecInput(input string, out chan interface{}, limit int) { @@ -257,8 +272,11 @@ func (s *Session) GetJson() ([]interface{}, error) { if s.err != nil { return nil, s.err } + s.envLock.Lock() + kill := s.kill + s.envLock.Unlock() select { - case <-s.kill: + case <-kill: return nil, ErrKillTimeout default: return s.dataOutput, nil From f5f0ed7173f20e3603dbe8144ac1bdfc432e452c Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Tue, 12 Aug 2014 14:30:05 -0400 Subject: [PATCH 3/4] Import gremlin, v=2 for more cases --- query/gremlin/finals.go | 1 + query/gremlin/session.go | 1 + 2 files changed, 2 insertions(+) diff --git a/query/gremlin/finals.go b/query/gremlin/finals.go index a82da13..6979e22 100644 --- a/query/gremlin/finals.go +++ b/query/gremlin/finals.go @@ -210,6 +210,7 @@ func runIteratorToArrayNoTags(it graph.Iterator, ses *Session, limit int) []stri func runIteratorWithCallback(it graph.Iterator, ses *Session, callback otto.Value, this otto.FunctionCall, limit int) { count := 0 it, _ = it.Optimize() + glog.V(2).Infoln(it.DebugString(0)) for { select { case <-ses.kill: diff --git a/query/gremlin/session.go b/query/gremlin/session.go index 8000c17..9e329c2 100644 --- a/query/gremlin/session.go +++ b/query/gremlin/session.go @@ -22,6 +22,7 @@ import ( "time" "github.com/robertkrimen/otto" + _ "github.com/robertkrimen/otto/underscore" "github.com/google/cayley/graph" "github.com/google/cayley/query" From b4ef86145d6c5c088aac179d502cf8b636d97a28 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Wed, 20 Aug 2014 15:56:36 -0400 Subject: [PATCH 4/4] Switch default to localhost. Fixes #107 --- config/config.go | 2 +- docs/Configuration.md | 2 +- docs/Overview.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index ff06e7c..26b68ac 100644 --- a/config/config.go +++ b/config/config.go @@ -126,7 +126,7 @@ var ( databasePath = flag.String("dbpath", "/tmp/testdb", "Path to the database.") databaseBackend = flag.String("db", "memstore", "Database Backend.") replicationBackend = flag.String("replication", "single", "Replication method.") - host = flag.String("host", "0.0.0.0", "Host to listen on (defaults to all).") + host = flag.String("host", "127.0.0.1", "Host to listen on (defaults to all).") loadSize = flag.Int("load_size", 10000, "Size of triplesets to load") port = flag.String("port", "64210", "Port to listen on.") readOnly = flag.Bool("read_only", false, "Disable writing via HTTP.") diff --git a/docs/Configuration.md b/docs/Configuration.md index b464adb..4b6b898 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -39,7 +39,7 @@ All command line flags take precedence over the configuration file. #### **`listen_host`** * Type: String - * Default: "0.0.0.0" + * Default: "127.0.0.1" The hostname or IP address for Cayley's HTTP server to listen on. Defaults to all interfaces. diff --git a/docs/Overview.md b/docs/Overview.md index cea43c6..300d005 100644 --- a/docs/Overview.md +++ b/docs/Overview.md @@ -62,7 +62,7 @@ Just as before: And you'll see a message not unlike ```bash -Cayley now listening on 0.0.0.0:64210 +Cayley now listening on 127.0.0.1:64210 ``` If you visit that address (often, [http://localhost:64210](http://localhost:64210)) you'll see the full web interface and also have a graph ready to serve queries via the [HTTP API](/docs/HTTP.md)