pSpaces / goSpace

Programming with Spaces in Go
MIT License
11 stars 5 forks source link

Blocking operators act as non-blocking operators if connection to remote spaces have not been established #13

Closed ghost closed 6 years ago

ghost commented 6 years ago

Due to current implementation, failing to immediately to establish a connection to a remote space, Put, Get and Query will act as non-blocking operators. Put, Get and Query should fail only if a communication error occurs during the operation, not when a connection needs to be established.

This causes unintended behaviour by continuing program execution at full speed.

This issue related to #1 and has similar effects as #12 when not using go.

Minimal example:

package main

import (
    "flag"
    "fmt"
    . "github.com/pspaces/gospace"
    "strings"
)

func main() {
    host, rport, lport := args()
    if host == "" {
        return
    }

    name := "space"

    ruri := strings.Join([]string{"tcp://", host, rport, "/", name}, "")

    rspc := NewRemoteSpace(ruri)

    luri := strings.Join([]string{"tcp://", "localhost", lport, "/", name}, "")

    lspc := NewSpace(luri)

    lspc.Put("ready")
    rspc.Get("ready")
}

func args() (host string, rport string, lport string) {
    flag.Parse()

    argn := flag.NArg()
    if argn > 3 {
        fmt.Printf("Usage of %s: [address] [rport] [lport]\n", "main")
        return
    }

    if argn >= 1 {
        host = flag.Arg(0)
    } else {
        host = "localhost"
    }

    if argn >= 2 {
        rport = strings.Join([]string{":", flag.Arg(1)}, "")
    }

    if argn == 3 {
        lport = strings.Join([]string{":", flag.Arg(2)}, "")
    }

    return host, rport, lport
}

Executing the following on peer 1:

go run main.go <peer-2-address> 31415 31416

And the following on peer 2:

go run main.go <peer-1-address> 31416 31415
albertolluch commented 6 years ago

Good observation. I don't get this sentence:

The implementation should ensure that when blocking operations occur, even if the connection can not yet be established.

It seems that some part of the sentence is missing. Can you please explain?

ghost commented 6 years ago

Updated the original issue.

What I meant was that when a connection needs to be established, the blocking operators should also block if the connection not set up. That is all.

ghost commented 6 years ago

This has been temporarily fixed in commit 6e4bea2979e88bb19840a6bf365ea4611a497cb1 in the aggregation-policy branch.