Re: [go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Tamás Gulácsi
database/sql.DB is a pool. If you don't want to close it, 
SetMaxIdleConns(1), or better, use a db.Conn().

stephan...@gmail.com a következőt írta (2020. szeptember 11., péntek, 
21:02:26 UTC+2):

> On Friday, 11 September 2020 at 21:04:11 UTC+3 mar...@gmail.com wrote:
>
>> Which sqlite driver are you using? That sounds like a bug.
>>
>
> "github.com/mattn/go-sqlite3"
>  
>
>>
>> On Fri, Sep 11, 2020 at 10:56 AM Stephan Lukits wrote:
>>
>>> I passed a string-type pointer (as last destination) to a sql.DB.Query 
>>> call which had a NULL value as field value. No error was returned
>>
>>
> Here I was wrong.  The error is returned by the Scan(...)-call (which I 
> didn't catch, these are my first steps with go ...)
> The reason why I was fixated on the Query-call was the way I tracked the 
> cause:
> I printed the functioning and not functioning DB-connection and saw that 
> they differ
> &{0 {:memory: 0xc0e0e0} 0 {0 0} [0xc000126a20] ...
> &{0 {:memory: 0xc0e0e0} 0 {0 0} [] ...
> at the slice. Pinging the non-functioning DB-connection put a new addres 
> into the empty slice, so I assumed that this slice holds the open 
> connections.
> Then I narroed the two lines until I found the line where the switch to 
> the empty slice happand which was oddly the Query-call.
>
> The Questions which remain are, dose this connection gets closed allways 
> when an error appears? Is it a bug? 
> Can I use the API to figure if this connection was closed? Ping doesn't 
> work because it just creates a new connection and pretends everything is 
> fine.
> My settings are:
> .SetMaxOpenConns(1)
> .SetConnMaxLifetime(0)
> .SetConnMaxIdleTime(0)
> (because I really don't want this connection to close ;)
>  
> Thanks Stephan
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/284619bd-4576-4d73-8696-fbd0e1865a34n%40googlegroups.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
Thanks Mhd and agree with the suggestion.
However, we are trying to catch a bug which happens in production on k8s &
hence trying to explore different options.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMjfk%2BhHEfsbcSrjqMarPbAWexdz5kF0WTJvdGMLuu9gpu-N9A%40mail.gmail.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Mhd Shulhan
Pada tanggal Sab, 12 Sep 2020 08.52, Siddhesh Divekar <
siddhesh.dive...@gmail.com> menulis:

> In writing to a file option, we would periodically write the file as it
> might turn out to be a huge file
> for the entire life of the pod to flush at once
>

Maybe, the obvious solution here is not using Kubernetes. Create a VM,
deploy the binary, ssh into it and run the binary manually, redirect
request to VM, and so on.

>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMh9%2BYB6TZq6TS7aYAq_EC_c3evXBqnnm-sLBeijcCFNN5Joow%40mail.gmail.com.


Re: [go-nuts] writing to net.Conn tcp socket

2020-09-11 Thread Mhd Shulhan
Pada tanggal Sab, 12 Sep 2020 02.54, Andy Hall 
menulis:

> if I have multiple clients connected to a tcp server and I wish to write
> back to specific connections I can record the net.Conn value and then use
> the Write method on it...but when using Println I get the following for two
> clients...
>
> &{{0xc94000}}
> &{{0xc94080}}
>
> which when testing with a simple write doesn't work...
>
> package main
> import "net"
> var c net.Conn = "&{{0xc94000}}"
> func writeConn(c net.Conn) {
> c.Write([]byte(string("Hello\n")))
> }
> func main() {
> writeConn(c)
> }
>
> ...and results in the following...
>
> cannot use "&{{0xc94000}}" (type string) as type net.Conn in assignment
>
> clearly using Println to output the net.Conn is not a viable var to use so
> how could I do this ? I intend to record each users net.Conn in a database
> which can then be queried as required.
>
> any help would be most greatly appreciated.
>


Either I miss something or Go has different socket concept, but last time I
learn this is not how the network socket works in general.

First, &{{0xc94000}} is the address of a variable. You can't convert an
address from string back to variable, because that would be security issue.
Usually socket connection is signed integer, in C you can assign integer
value to variable let other process write into it. But in Go, connection is
an interface/structure.

If you want to record each users, you have two options:

1) Let the user send unique ID (for example their user ID or email or
username) on first accept.

2) Get unique ID from connection IP address (beware that two or more
connection may come from the same IP address).

You then must have a map that store unique ID as key and net.Conn as value.
So, if you want to send some value to specific user, you query the map
first and if exist then you can proceeds.

I hope that helps.

>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMh9%2BYA1t4ii3QgjMitYKPygQmPCxAJSSaJnctFy5i1t8zKjzA%40mail.gmail.com.


[go-nuts] Re: add method to interface via reflect

2020-09-11 Thread tapi...@gmail.com
What should happen after the method is added?
Will those types implementing the interface still implement it?

On Thursday, September 10, 2020 at 6:44:29 PM UTC-4 va...@selfip.ru wrote:

> Hi! Does go support adding method to exiting interface via reflect?
> Mostly I need to add method to struct pointer.
>
> -- 
> Vasiliy Tolstov,
> e-mail: v.to...@selfip.ru
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a6dbd320-800c-4423-8899-d1fa74f921bcn%40googlegroups.com.


[go-nuts] Re: godoc-static - Generate static documentation for your packages

2020-09-11 Thread tapi...@gmail.com
Cool.

BTW, there is another docs generator: https://github.com/go101/gold 
(written by me).

On Thursday, February 6, 2020 at 7:56:15 PM UTC-5 Trevor Slocum wrote:

> Repository: https://gitlab.com/tslocum/godoc-static
>
> Demo output: https://docs.rocketnine.space
>
> Inspired by the recent news of godoc.org shutting down I have created 
> godoc-static.  While we could all migrate to pkg.go.dev, we could also 
> host and update our documentation ourselves. 
>
> When invoked, "godoc -http=localhost:" is started, relevant package 
> documentation pages and source code is scraped and rewritten to fix 
> styling, expanding content, etc., then godoc is terminated. 
>
> Note that while things seem to work, I have only focused on shipping the 
> MVP so far.  Here be dragons.  For instance, to get this to work on my VPS 
> I had to set  GO111MODULE to off and clone relevant package sources to 
> GOPATH.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fe350dfa-296f-4430-a19b-d82afa2629f0n%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
Still a mistake there. All "MyReader" uses should be "*MyReader".

On Friday, September 11, 2020 at 11:02:49 PM UTC-4 Di gg wrote:

> Sorry, the last 4 lines should be:
>
> rs = (MyReader string)(rb)
> _, _ = rs.Read(s)
> rb = (MyReader []byte)(rs)
> _, _ = rb.Read(bs)
>
> On Friday, September 11, 2020 at 11:00:12 PM UTC-4 Di gg wrote:
>
>> An example demostrating how to let Reader.Read support both string and 
>> []byte parameters.
>>
>> package readonlybytes[T] (
>> assert T.kind & (String | Slice)
>> )
>>
>> package Reader[T] (
>> assert readonlybytes[T]
>> ){
>> type Reader interface {
>> Read(bytes T)(n int, err error)
>> }
>> }
>>
>> package MyReader[T](
>> assert T.kind & (String | Slice)
>> ){
>> type MyReader struct{}
>>
>> type (r *MyReader) Read(s T)(int, error) {
>> return len(s), nil
>> }
>> }
>>
>> // use it:
>>
>> var mrs MyReader string
>> var mrb MyReader []byte
>>
>> s := "Golang"
>> bs := make([]byte, 100)
>>
>> var rs Reader string = mrs
>> _, _ = rs.Read(s)
>> var rb Reader []byte = mrb
>> _, _ = rb.Read(bs)
>>
>> rb = (MyReader string)(rs)
>> _, _ = rb.Read(bs)
>> rs = (MyReader []byte)(rb)
>> _, _ = rs.Read(s)
>>
>>
>>
>> On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:
>>
>>>
>>>
>>> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>>>
>>> This is an alternative generic idea set, which should be Go 1 compatible.
>>> It tries to use the same syntax forms as builtin generics.
>>>
>>> Different from the official draft, it adopts a from-top-to-bottom 
>>> pattern,
>>> instead of the from-bottom-to-top pattern, to describe type parameters.
>>> For example, given a map type parameter M, its key and element types 
>>> could
>>> be denoted as M.key and M.element, whereas to use a map type parameter,
>>> its key and elements must also present in the declaration signarure or 
>>> constraint definitions.
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d465715d-c381-486e-8a1f-617a68f82b59n%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
Sorry, the last 4 lines should be:

rs = (MyReader string)(rb)
_, _ = rs.Read(s)
rb = (MyReader []byte)(rs)
_, _ = rb.Read(bs)

On Friday, September 11, 2020 at 11:00:12 PM UTC-4 Di gg wrote:

> An example demostrating how to let Reader.Read support both string and 
> []byte parameters.
>
> package readonlybytes[T] (
> assert T.kind & (String | Slice)
> )
>
> package Reader[T] (
> assert readonlybytes[T]
> ){
> type Reader interface {
> Read(bytes T)(n int, err error)
> }
> }
>
> package MyReader[T](
> assert T.kind & (String | Slice)
> ){
> type MyReader struct{}
>
> type (r *MyReader) Read(s T)(int, error) {
> return len(s), nil
> }
> }
>
> // use it:
>
> var mrs MyReader string
> var mrb MyReader []byte
>
> s := "Golang"
> bs := make([]byte, 100)
>
> var rs Reader string = mrs
> _, _ = rs.Read(s)
> var rb Reader []byte = mrb
> _, _ = rb.Read(bs)
>
> rb = (MyReader string)(rs)
> _, _ = rb.Read(bs)
> rs = (MyReader []byte)(rb)
> _, _ = rs.Read(s)
>
>
>
> On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:
>
>>
>>
>> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>>
>> This is an alternative generic idea set, which should be Go 1 compatible.
>> It tries to use the same syntax forms as builtin generics.
>>
>> Different from the official draft, it adopts a from-top-to-bottom pattern,
>> instead of the from-bottom-to-top pattern, to describe type parameters.
>> For example, given a map type parameter M, its key and element types could
>> be denoted as M.key and M.element, whereas to use a map type parameter,
>> its key and elements must also present in the declaration signarure or 
>> constraint definitions.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/89a51517-3b2b-46a9-ae72-70a01172bfccn%40googlegroups.com.


[go-nuts] Re: some interesting ideas: reuse package keyword to declare generics

2020-09-11 Thread Di gg
An example demostrating how to let Reader.Read support both string and 
[]byte parameters.

package readonlybytes[T] (
assert T.kind & (String | Slice)
)

package Reader[T] (
assert readonlybytes[T]
){
type Reader interface {
Read(bytes T)(n int, err error)
}
}

package MyReader[T](
assert T.kind & (String | Slice)
){
type MyReader struct{}

type (r *MyReader) Read(s T)(int, error) {
return len(s), nil
}
}

// use it:

var mrs MyReader string
var mrb MyReader []byte

s := "Golang"
bs := make([]byte, 100)

var rs Reader string = mrs
_, _ = rs.Read(s)
var rb Reader []byte = mrb
_, _ = rb.Read(bs)

rb = (MyReader string)(rs)
_, _ = rb.Read(bs)
rs = (MyReader []byte)(rb)
_, _ = rs.Read(s)



On Wednesday, August 26, 2020 at 1:16:49 PM UTC-4 Di gg wrote:

>
>
> https://github.com/dotaheor/unify-Go-builtin-and-custom-generics/blob/master/use-package-as-gen.md
>
> This is an alternative generic idea set, which should be Go 1 compatible.
> It tries to use the same syntax forms as builtin generics.
>
> Different from the official draft, it adopts a from-top-to-bottom pattern,
> instead of the from-bottom-to-top pattern, to describe type parameters.
> For example, given a map type parameter M, its key and element types could
> be denoted as M.key and M.element, whereas to use a map type parameter,
> its key and elements must also present in the declaration signarure or 
> constraint definitions.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cd343e62-925f-4185-af3d-8c04c16aefbfn%40googlegroups.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
In writing to a file option, we would periodically write the file as it
might turn out to be a huge file
for the entire life of the pod to flush at once.

On Fri, Sep 11, 2020 at 6:32 PM Siddhesh Divekar 
wrote:

> You need to write to a shared writable path that is global so when the pod
>> terminated the file is avail.
>
> That's a good idea, we can write to to a config map.
>
> The http should work too if you map the ports properly. You can be able to
>> access the port from outside the pod.
>
> This might not work. When the issue happened last time, prometheus was
> unable to pull any metrics from the pod.
> For the entire period prometheus output was blank which told us that the
> pod was non-responsive.
>
> On Fri, Sep 11, 2020 at 5:59 PM Robert Engels 
> wrote:
>
>> You need to write to a shared writable path that is global so when the
>> pod terminated the file is avail.
>>
>> The http should work too if you map the ports properly. You can be able
>> to access the port from outside the pod.
>>
>> On Sep 11, 2020, at 7:14 PM, Siddhesh Divekar 
>> wrote:
>>
>> 
>> I went through the suggested approaches and here are my thoughts.
>>
>> - runtime/trace.Start - The example in the doc
>> https://golang.org/pkg/runtime/trace/ suggests adding
>> os.Create("trace.out"), trace.Start &
>> defer trace.Stop in the main before the application program gets started.
>> In an environment like k8s if the executing program is the pod main
>> program then the pod will terminate and the trace.out will be lost.
>>
>> - net/http/pprof package - This has the same problem where requests might
>> not make to the http server.
>>
>> - go test -trace - Works with only tests
>>
>> Any thoughts/ideas of what we can do to get a trace file avoiding above
>> issues ?
>>
>> On Fri, Sep 11, 2020 at 12:06 PM Robert Engels 
>> wrote:
>>
>>> Please read golang.org/cmd/trace
>>>
>>> You need a trace file. There are many ways to capture one.
>>>
>>> On Sep 11, 2020, at 12:09 PM, Siddhesh Divekar <
>>> siddhesh.dive...@gmail.com> wrote:
>>>
>>> 
>>> Ok, let me get them working first.
>>>
>>> My concern with pprof is it has to be made part of my process.
>>> We had an issue where user requests were not reaching our http server
>>> itself.
>>>
>>> In this case what are my options if pprof server is not reachable when
>>> we hit the same issue again.
>>> Are there any other tools which can be run independently?
>>>
>>> On Fri, Sep 11, 2020 at 5:20 AM Robert Engels 
>>> wrote:
>>>
 I would start with making sure you can get the standard ‘go tool trace’
 and ‘pprof’ working. Once you have those working ‘goanalyzer’ is an
 enhanced version.

 The docs are far more complete and substantial on the standard tools.

 On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar <
 siddhesh.dive...@gmail.com> wrote:

 
 Is there any dependency on GOPATH while running `./goanalyzer binary
 trace-file` ?
 Also my goanalyzer is built on mac and am trying to look at trace file
 generated on ubuntu (shouldn't be a problem).

 ./goanalyzer ~/workspace/binary  ~/workspace/trace
 2020/09/10 23:27:32 Parsing trace...
 2020/09/10 23:27:32 Splitting trace...
 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on
 http://127.0.0.1:55520

 If I try to go to a particular go routing eg
 http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.

 Clicking on any of the graphs for a goroutine says the following.

 failed to execute go tool pprof: exit status 1
 failed to execute dot. Is Graphviz installed? Error: exec: "dot": 
 executable file not found in $PATH


 On Thu, Sep 10, 2020 at 4:49 PM robert engels 
 wrote:

> goanalyzer = go tool trace
>
> The options to goanalyzer are the same as ‘go tool trace’ - the usage
> message is misleading in this way.
>
> By ‘map’ I mean expose the pprof port as you would any other port, and
> yes you use the net/http/pprof to start the internal webserver - you don’t
> need to create your own.
>
>
>
> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar <
> siddhesh.dive...@gmail.com> wrote:
>
> Hi Robert,
>
> Laying down the steps to make sure I understood it correctly.
>
> You can map the port
>>
> What did you mean by above ?
>
> but might be easier to capture to a file via code and use goanalyzer
>> on the file
>>
> In this case I will do the following.
> a) Set up a webserver in my program for getting Go profiles (with
> import _ "net/http/pprof")
> b) map a port from outside k8s so that i can run curl
> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say
> profile-file)
> c) Use go tool pprof/goanalyzer to analyze given profile from the
> profile-file
>
> I would prefer to run this outside my process as the issue we expect
> to 

Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
>
> You need to write to a shared writable path that is global so when the pod
> terminated the file is avail.

That's a good idea, we can write to to a config map.

The http should work too if you map the ports properly. You can be able to
> access the port from outside the pod.

This might not work. When the issue happened last time, prometheus was
unable to pull any metrics from the pod.
For the entire period prometheus output was blank which told us that the
pod was non-responsive.

On Fri, Sep 11, 2020 at 5:59 PM Robert Engels  wrote:

> You need to write to a shared writable path that is global so when the pod
> terminated the file is avail.
>
> The http should work too if you map the ports properly. You can be able to
> access the port from outside the pod.
>
> On Sep 11, 2020, at 7:14 PM, Siddhesh Divekar 
> wrote:
>
> 
> I went through the suggested approaches and here are my thoughts.
>
> - runtime/trace.Start - The example in the doc
> https://golang.org/pkg/runtime/trace/ suggests adding
> os.Create("trace.out"), trace.Start &
> defer trace.Stop in the main before the application program gets started.
> In an environment like k8s if the executing program is the pod main
> program then the pod will terminate and the trace.out will be lost.
>
> - net/http/pprof package - This has the same problem where requests might
> not make to the http server.
>
> - go test -trace - Works with only tests
>
> Any thoughts/ideas of what we can do to get a trace file avoiding above
> issues ?
>
> On Fri, Sep 11, 2020 at 12:06 PM Robert Engels 
> wrote:
>
>> Please read golang.org/cmd/trace
>>
>> You need a trace file. There are many ways to capture one.
>>
>> On Sep 11, 2020, at 12:09 PM, Siddhesh Divekar <
>> siddhesh.dive...@gmail.com> wrote:
>>
>> 
>> Ok, let me get them working first.
>>
>> My concern with pprof is it has to be made part of my process.
>> We had an issue where user requests were not reaching our http server
>> itself.
>>
>> In this case what are my options if pprof server is not reachable when we
>> hit the same issue again.
>> Are there any other tools which can be run independently?
>>
>> On Fri, Sep 11, 2020 at 5:20 AM Robert Engels 
>> wrote:
>>
>>> I would start with making sure you can get the standard ‘go tool trace’
>>> and ‘pprof’ working. Once you have those working ‘goanalyzer’ is an
>>> enhanced version.
>>>
>>> The docs are far more complete and substantial on the standard tools.
>>>
>>> On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar <
>>> siddhesh.dive...@gmail.com> wrote:
>>>
>>> 
>>> Is there any dependency on GOPATH while running `./goanalyzer binary
>>> trace-file` ?
>>> Also my goanalyzer is built on mac and am trying to look at trace file
>>> generated on ubuntu (shouldn't be a problem).
>>>
>>> ./goanalyzer ~/workspace/binary  ~/workspace/trace
>>> 2020/09/10 23:27:32 Parsing trace...
>>> 2020/09/10 23:27:32 Splitting trace...
>>> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on
>>> http://127.0.0.1:55520
>>>
>>> If I try to go to a particular go routing eg
>>> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
>>>
>>> Clicking on any of the graphs for a goroutine says the following.
>>>
>>> failed to execute go tool pprof: exit status 1
>>> failed to execute dot. Is Graphviz installed? Error: exec: "dot": 
>>> executable file not found in $PATH
>>>
>>>
>>> On Thu, Sep 10, 2020 at 4:49 PM robert engels 
>>> wrote:
>>>
 goanalyzer = go tool trace

 The options to goanalyzer are the same as ‘go tool trace’ - the usage
 message is misleading in this way.

 By ‘map’ I mean expose the pprof port as you would any other port, and
 yes you use the net/http/pprof to start the internal webserver - you don’t
 need to create your own.



 On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar <
 siddhesh.dive...@gmail.com> wrote:

 Hi Robert,

 Laying down the steps to make sure I understood it correctly.

 You can map the port
>
 What did you mean by above ?

 but might be easier to capture to a file via code and use goanalyzer on
> the file
>
 In this case I will do the following.
 a) Set up a webserver in my program for getting Go profiles (with
 import _ "net/http/pprof")
 b) map a port from outside k8s so that i can run curl
 localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say
 profile-file)
 c) Use go tool pprof/goanalyzer to analyze given profile from the
 profile-file

 I would prefer to run this outside my process as the issue we expect to
 happen is when my program is hung.
 I am not sure if the http server would respond & generate profile files.

 From the help of goanalyzer it's not very clear how I would pass the
 profile-file to it.
 It's showing how to generate profile-file using go test/tool but not
 how to pass them to goanalyzer.

 # ./goanalyzer -h

Re: [go-nuts] alloc vs totalalloc in memory

2020-09-11 Thread Robert Engels
Because memory is reclaimed - the alloc is the “live” heap. TotalAlloc is a 
cumulative counter of byte allocated - bytes freed do not affect the counter. 

> On Sep 11, 2020, at 7:14 PM, Alexander Mills  
> wrote:
> 
> 
> Well why does TotalAlloc keep climbing up (increasing) in my program, but 
> HeapAlloc remains the same?
> 
> 
> 
> 
> 
>> On Fri, Sep 11, 2020 at 5:06 PM Ian Lance Taylor  wrote:
>> On Fri, Sep 11, 2020 at 5:01 PM Alex Mills  wrote:
>> >
>> > The explanations I find online arent very clear to me :(
>> 
>> Well, OK, but I don't know what I can say other than to repeat the
>> information from that link.
>> 
>> Alloc is bytes of allocated heap objects.
>> 
>> TotalAlloc is cumulative bytes allocated for heap objects.
>> 
>> If that is not clear, what is not clear about it?
>> 
>> Ian
>> 
>> 
>> > On Thursday, September 10, 2020 at 6:40:34 PM UTC-7 Ian Lance Taylor wrote:
>> >>
>> >> On Thu, Sep 10, 2020 at 4:39 PM Alexander Mills
>> >>  wrote:
>> >> >
>> >> > I have this helper func to print memory usage (detect a memory leak?)
>> >> >
>> >> >
>> >> > func PrintMemUsage() {
>> >> > var m runtime.MemStats
>> >> > runtime.ReadMemStats()
>> >> > // For info on each, see: https://golang.org/pkg/runtime/#MemStats
>> >> > fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
>> >> > fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
>> >> > fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
>> >> > fmt.Printf("\tNumGC = %v\n", m.NumGC)
>> >> > }
>> >> >
>> >> > I am seeing output like this:
>> >> > Alloc = 2481 MiB TotalAlloc = 24038 MiB Sys = 2752 MiB NumGC = 114
>> >> >
>> >> > what is the difference between Alloc and TotalAlloc .. ?
>> >>
>> >> The link above, after "For info on each", explains the difference. If
>> >> the explanation is unclear, tell us more.
>> >>
>> >> Ian
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups 
>> > "golang-nuts" group.
>> > To unsubscribe from this group and stop receiving emails from it, send an 
>> > email to golang-nuts+unsubscr...@googlegroups.com.
>> > To view this discussion on the web visit 
>> > https://groups.google.com/d/msgid/golang-nuts/6c889d9b-e2f1-4583-b310-8954ce456852n%40googlegroups.com.
>> 
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/zLxLN03h6LQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXQ4eedgwwnxT0Hg_3%2BWmjexX1NriT26U1AksEVmrW8sg%40mail.gmail.com.
> 
> 
> -- 
> Alexander D. Mills
> New cell phone # (415)730-1805
> linkedin.com/in/alexanderdmills
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CA%2BKyZp6Jrto_x533zaY5jLWMo7%2Bqa8aAsufLqwdSR1voM6pMaw%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/308EA873-C7EF-460A-AA87-F709A8A43993%40ix.netcom.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Robert Engels
You need to write to a shared writable path that is global so when the pod 
terminated the file is avail. 

The http should work too if you map the ports properly. You can be able to 
access the port from outside the pod. 

> On Sep 11, 2020, at 7:14 PM, Siddhesh Divekar  
> wrote:
> 
> 
> I went through the suggested approaches and here are my thoughts.
> 
> - runtime/trace.Start - The example in the doc 
> https://golang.org/pkg/runtime/trace/ suggests adding os.Create("trace.out"), 
> trace.Start & 
> defer trace.Stop in the main before the application program gets started.
> In an environment like k8s if the executing program is the pod main program 
> then the pod will terminate and the trace.out will be lost. 
> 
> - net/http/pprof package - This has the same problem where requests might not 
> make to the http server.
> 
> - go test -trace - Works with only tests
> 
> Any thoughts/ideas of what we can do to get a trace file avoiding above 
> issues ?
> 
>> On Fri, Sep 11, 2020 at 12:06 PM Robert Engels  wrote:
>> Please read golang.org/cmd/trace
>> 
>> You need a trace file. There are many ways to capture one. 
>> 
 On Sep 11, 2020, at 12:09 PM, Siddhesh Divekar 
  wrote:
 
>>> 
>>> Ok, let me get them working first.
>>> 
>>> My concern with pprof is it has to be made part of my process.
>>> We had an issue where user requests were not reaching our http server 
>>> itself.
>>> 
>>> In this case what are my options if pprof server is not reachable when we 
>>> hit the same issue again.
>>> Are there any other tools which can be run independently?
>>> 
 On Fri, Sep 11, 2020 at 5:20 AM Robert Engels  
 wrote:
 I would start with making sure you can get the standard ‘go tool trace’ 
 and ‘pprof’ working. Once you have those working ‘goanalyzer’ is an 
 enhanced version. 
 
 The docs are far more complete and substantial on the standard tools. 
 
>> On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar 
>>  wrote:
>> 
> 
> Is there any dependency on GOPATH while running `./goanalyzer binary 
> trace-file` ?
> Also my goanalyzer is built on mac and am trying to look at trace file 
> generated on ubuntu (shouldn't be a problem).
> 
> ./goanalyzer ~/workspace/binary  ~/workspace/trace
> 2020/09/10 23:27:32 Parsing trace...
> 2020/09/10 23:27:32 Splitting trace...
> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on 
> http://127.0.0.1:55520
> 
> If I try to go to a particular go routing eg 
> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
> 
> Clicking on any of the graphs for a goroutine says the following.
> failed to execute go tool pprof: exit status 1
> failed to execute dot. Is Graphviz installed? Error: exec: "dot": 
> executable file not found in $PATH
> 
>> On Thu, Sep 10, 2020 at 4:49 PM robert engels  
>> wrote:
>> goanalyzer = go tool trace
>> 
>> The options to goanalyzer are the same as ‘go tool trace’ - the usage 
>> message is misleading in this way.
>> 
>> By ‘map’ I mean expose the pprof port as you would any other port, and 
>> yes you use the net/http/pprof to start the internal webserver - you 
>> don’t need to create your own.
>> 
>> 
>> 
>>> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar 
>>>  wrote:
>>> 
>>> Hi Robert,
>>> 
>>> Laying down the steps to make sure I understood it correctly.
>>> 
 You can map the port 
>>> What did you mean by above ? 
>>> 
 but might be easier to capture to a file via code and use goanalyzer 
 on the file
>>> In this case I will do the following.
>>> a) Set up a webserver in my program for getting Go profiles (with 
>>> import _ "net/http/pprof")
>>> b) map a port from outside k8s so that i can run curl 
>>> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say 
>>> profile-file)
>>> c) Use go tool pprof/goanalyzer to analyze given profile from the 
>>> profile-file
>>> 
>>> I would prefer to run this outside my process as the issue we expect to 
>>> happen is when my program is hung.
>>> I am not sure if the http server would respond & generate profile files.
>>> 
>>> From the help of goanalyzer it's not very clear how I would pass the 
>>> profile-file to it.
>>> It's showing how to generate profile-file using go test/tool but not 
>>> how to pass them to goanalyzer.
>>> 
>>> # ./goanalyzer -h
>>> Usage of 'go tool trace':
>>> Given a trace file produced by 'go test':
>>> go test -trace=trace.out pkg
>>> 
>>> Open a web browser displaying trace:
>>> go tool trace [flags] [pkg.test] trace.out
>>> 
>>> Generate a pprof-like profile from the trace:
>>> go tool trace -pprof=TYPE [pkg.test] trace.out
>>> 
>>> [pkg.test] argument is required for 

Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
I went through the suggested approaches and here are my thoughts.

- runtime/trace.Start - The example in the doc
https://golang.org/pkg/runtime/trace/ suggests adding
os.Create("trace.out"), trace.Start &
defer trace.Stop in the main before the application program gets started.
In an environment like k8s if the executing program is the pod main program
then the pod will terminate and the trace.out will be lost.

- net/http/pprof package - This has the same problem where requests might
not make to the http server.

- go test -trace - Works with only tests

Any thoughts/ideas of what we can do to get a trace file avoiding above
issues ?

On Fri, Sep 11, 2020 at 12:06 PM Robert Engels 
wrote:

> Please read golang.org/cmd/trace
>
> You need a trace file. There are many ways to capture one.
>
> On Sep 11, 2020, at 12:09 PM, Siddhesh Divekar 
> wrote:
>
> 
> Ok, let me get them working first.
>
> My concern with pprof is it has to be made part of my process.
> We had an issue where user requests were not reaching our http server
> itself.
>
> In this case what are my options if pprof server is not reachable when we
> hit the same issue again.
> Are there any other tools which can be run independently?
>
> On Fri, Sep 11, 2020 at 5:20 AM Robert Engels 
> wrote:
>
>> I would start with making sure you can get the standard ‘go tool trace’
>> and ‘pprof’ working. Once you have those working ‘goanalyzer’ is an
>> enhanced version.
>>
>> The docs are far more complete and substantial on the standard tools.
>>
>> On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar 
>> wrote:
>>
>> 
>> Is there any dependency on GOPATH while running `./goanalyzer binary
>> trace-file` ?
>> Also my goanalyzer is built on mac and am trying to look at trace file
>> generated on ubuntu (shouldn't be a problem).
>>
>> ./goanalyzer ~/workspace/binary  ~/workspace/trace
>> 2020/09/10 23:27:32 Parsing trace...
>> 2020/09/10 23:27:32 Splitting trace...
>> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on
>> http://127.0.0.1:55520
>>
>> If I try to go to a particular go routing eg
>> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
>>
>> Clicking on any of the graphs for a goroutine says the following.
>>
>> failed to execute go tool pprof: exit status 1
>> failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable 
>> file not found in $PATH
>>
>>
>> On Thu, Sep 10, 2020 at 4:49 PM robert engels 
>> wrote:
>>
>>> goanalyzer = go tool trace
>>>
>>> The options to goanalyzer are the same as ‘go tool trace’ - the usage
>>> message is misleading in this way.
>>>
>>> By ‘map’ I mean expose the pprof port as you would any other port, and
>>> yes you use the net/http/pprof to start the internal webserver - you don’t
>>> need to create your own.
>>>
>>>
>>>
>>> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar <
>>> siddhesh.dive...@gmail.com> wrote:
>>>
>>> Hi Robert,
>>>
>>> Laying down the steps to make sure I understood it correctly.
>>>
>>> You can map the port

>>> What did you mean by above ?
>>>
>>> but might be easier to capture to a file via code and use goanalyzer on
 the file

>>> In this case I will do the following.
>>> a) Set up a webserver in my program for getting Go profiles (with import
>>> _ "net/http/pprof")
>>> b) map a port from outside k8s so that i can run curl
>>> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say
>>> profile-file)
>>> c) Use go tool pprof/goanalyzer to analyze given profile from the
>>> profile-file
>>>
>>> I would prefer to run this outside my process as the issue we expect to
>>> happen is when my program is hung.
>>> I am not sure if the http server would respond & generate profile files.
>>>
>>> From the help of goanalyzer it's not very clear how I would pass the
>>> profile-file to it.
>>> It's showing how to generate profile-file using go test/tool but not how
>>> to pass them to goanalyzer.
>>>
>>> # ./goanalyzer -h
>>> Usage of 'go tool trace':
>>> Given a trace file produced by 'go test':
>>> go test -trace=trace.out pkg
>>>
>>> Open a web browser displaying trace:
>>> go tool trace [flags] [pkg.test] trace.out
>>>
>>> Generate a pprof-like profile from the trace:
>>> go tool trace -pprof=TYPE [pkg.test] trace.out
>>>
>>> [pkg.test] argument is required for traces produced by Go 1.6 and below.
>>> Go 1.7 does not require the binary argument.
>>>
>>> Supported profile types are:
>>> - net: network blocking profile
>>> - sync: synchronization blocking profile
>>> - syscall: syscall blocking profile
>>> - sched: scheduler latency profile
>>>
>>> Flags:
>>> -http=addr: HTTP service address (e.g., ':6060')
>>> -pprof=type: print a pprof-like profile instead
>>> -d: print debug info such as parsed events
>>>
>>>
>>> On Thu, Sep 10, 2020 at 3:22 PM Robert Engels 
>>> wrote:
>>>
 You can map the port but might be easier to capture to a file via code
 and use goanalyzer on the file.

 On Sep 10, 2020, 

Re: [go-nuts] alloc vs totalalloc in memory

2020-09-11 Thread Ian Lance Taylor
On Fri, Sep 11, 2020 at 5:01 PM Alex Mills  wrote:
>
> The explanations I find online arent very clear to me :(

Well, OK, but I don't know what I can say other than to repeat the
information from that link.

Alloc is bytes of allocated heap objects.

TotalAlloc is cumulative bytes allocated for heap objects.

If that is not clear, what is not clear about it?

Ian


> On Thursday, September 10, 2020 at 6:40:34 PM UTC-7 Ian Lance Taylor wrote:
>>
>> On Thu, Sep 10, 2020 at 4:39 PM Alexander Mills
>>  wrote:
>> >
>> > I have this helper func to print memory usage (detect a memory leak?)
>> >
>> >
>> > func PrintMemUsage() {
>> > var m runtime.MemStats
>> > runtime.ReadMemStats()
>> > // For info on each, see: https://golang.org/pkg/runtime/#MemStats
>> > fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
>> > fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
>> > fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
>> > fmt.Printf("\tNumGC = %v\n", m.NumGC)
>> > }
>> >
>> > I am seeing output like this:
>> > Alloc = 2481 MiB TotalAlloc = 24038 MiB Sys = 2752 MiB NumGC = 114
>> >
>> > what is the difference between Alloc and TotalAlloc .. ?
>>
>> The link above, after "For info on each", explains the difference. If
>> the explanation is unclear, tell us more.
>>
>> Ian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/6c889d9b-e2f1-4583-b310-8954ce456852n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXQ4eedgwwnxT0Hg_3%2BWmjexX1NriT26U1AksEVmrW8sg%40mail.gmail.com.


Re: [go-nuts] Re: Is there a gui library for Go, like Gtk+ or similar, which can be used to build statically linked executables ?

2020-09-11 Thread Philip Chapman
There is a gtk binding, but I'm not sure if it's fully cross platform.

https://github.com/gotk3/gotk3

On Fri, Sep 11, 2020, 6:26 PM Kent Sandvik  wrote:

> I tested fyne on my Mac, hey didn't crash, that's a big plus with these
> cross-platform GUI frameworks. The Look is somewhat different but with
> some tweaks it could be made manageable. But for any large text-based
> application with text styling and so forth  I would use Electron or a
> similar browser-engine framework. --Kent
>
> On Fri, Sep 11, 2020 at 2:58 PM Serge Hulne  wrote:
>
>> I had a look again at "Fyne". It seems to have improved a lot lately, in
>> particular the default size for fonts etc seems much better!
>> Thanks again for the suggestion.
>>
>> On Sunday, 2 August 2020 at 23:43:56 UTC+2 ma...@eliasnaur.com wrote:
>>
>>> On Sunday, 2 August 2020 at 23:24:20 UTC+2 jake...@gmail.com wrote:
>>>
 There is currently no 'clear choice' for GUI in go. It will depend on
 you needs. Some to look into:

 https://bitbucket.org/rj/goey/src/master/
 https://gioui.org/
 https://github.com/andlabs/ui
 https://github.com/goki/gi
 https://github.com/lxn/walk

>>>
>>> There's also https://fyne.io.
>>>
>>> Elias
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/729a782e-d87f-4ca9-9a08-740fd758d2a6n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAHC_roHE9sTye127Gd%3DfxvDNXZU_R-yUdazpuskyxHfL9bkOiw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABEejshannDE0XtX2O%3Dkomgm6rtV7Umf0SnZ-w3Uf0TFi7DrQQ%40mail.gmail.com.


Re: [go-nuts] alloc vs totalalloc in memory

2020-09-11 Thread Alex Mills
The explanations I find online arent very clear to me :(

On Thursday, September 10, 2020 at 6:40:34 PM UTC-7 Ian Lance Taylor wrote:

> On Thu, Sep 10, 2020 at 4:39 PM Alexander Mills
>  wrote:
> >
> > I have this helper func to print memory usage (detect a memory leak?)
> >
> >
> > func PrintMemUsage() {
> > var m runtime.MemStats
> > runtime.ReadMemStats()
> > // For info on each, see: https://golang.org/pkg/runtime/#MemStats
> > fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
> > fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
> > fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
> > fmt.Printf("\tNumGC = %v\n", m.NumGC)
> > }
> >
> > I am seeing output like this:
> > Alloc = 2481 MiB TotalAlloc = 24038 MiB Sys = 2752 MiB NumGC = 114
> >
> > what is the difference between Alloc and TotalAlloc .. ?
>
> The link above, after "For info on each", explains the difference. If
> the explanation is unclear, tell us more.
>
> Ian
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/6c889d9b-e2f1-4583-b310-8954ce456852n%40googlegroups.com.


Re: [go-nuts] Re: Is there a gui library for Go, like Gtk+ or similar, which can be used to build statically linked executables ?

2020-09-11 Thread Kent Sandvik
I tested fyne on my Mac, hey didn't crash, that's a big plus with these
cross-platform GUI frameworks. The Look is somewhat different but with
some tweaks it could be made manageable. But for any large text-based
application with text styling and so forth  I would use Electron or a
similar browser-engine framework. --Kent

On Fri, Sep 11, 2020 at 2:58 PM Serge Hulne  wrote:

> I had a look again at "Fyne". It seems to have improved a lot lately, in
> particular the default size for fonts etc seems much better!
> Thanks again for the suggestion.
>
> On Sunday, 2 August 2020 at 23:43:56 UTC+2 ma...@eliasnaur.com wrote:
>
>> On Sunday, 2 August 2020 at 23:24:20 UTC+2 jake...@gmail.com wrote:
>>
>>> There is currently no 'clear choice' for GUI in go. It will depend on
>>> you needs. Some to look into:
>>>
>>> https://bitbucket.org/rj/goey/src/master/
>>> https://gioui.org/
>>> https://github.com/andlabs/ui
>>> https://github.com/goki/gi
>>> https://github.com/lxn/walk
>>>
>>
>> There's also https://fyne.io.
>>
>> Elias
>>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/729a782e-d87f-4ca9-9a08-740fd758d2a6n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAHC_roHE9sTye127Gd%3DfxvDNXZU_R-yUdazpuskyxHfL9bkOiw%40mail.gmail.com.


[go-nuts] Re: Is there a gui library for Go, like Gtk+ or similar, which can be used to build statically linked executables ?

2020-09-11 Thread Serge Hulne
I had a look again at "Fyne". It seems to have improved a lot lately, in 
particular the default size for fonts etc seems much better!
Thanks again for the suggestion.

On Sunday, 2 August 2020 at 23:43:56 UTC+2 ma...@eliasnaur.com wrote:

> On Sunday, 2 August 2020 at 23:24:20 UTC+2 jake...@gmail.com wrote:
>
>> There is currently no 'clear choice' for GUI in go. It will depend on you 
>> needs. Some to look into:
>>
>> https://bitbucket.org/rj/goey/src/master/
>> https://gioui.org/
>> https://github.com/andlabs/ui
>> https://github.com/goki/gi
>> https://github.com/lxn/walk
>>
>
> There's also https://fyne.io.
>
> Elias
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/729a782e-d87f-4ca9-9a08-740fd758d2a6n%40googlegroups.com.


[go-nuts] writing to net.Conn tcp socket

2020-09-11 Thread Andy Hall
if I have multiple clients connected to a tcp server and I wish to write 
back to specific connections I can record the net.Conn value and then use 
the Write method on it...but when using Println I get the following for two 
clients...

&{{0xc94000}}
&{{0xc94080}}

which when testing with a simple write doesn't work...

package main
import "net"
var c net.Conn = "&{{0xc94000}}"
func writeConn(c net.Conn) {
c.Write([]byte(string("Hello\n")))
}
func main() {
writeConn(c)
}

...and results in the following...

cannot use "&{{0xc94000}}" (type string) as type net.Conn in assignment

clearly using Println to output the net.Conn is not a viable var to use so 
how could I do this ? I intend to record each users net.Conn in a database 
which can then be queried as required.

any help would be most greatly appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9d93a9b7-fd81-4586-adbb-be6b3996e727n%40googlegroups.com.


Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Kevin Chadwick
On 2020-09-11 19:08, Ian Lance Taylor wrote:
> The way Go works, ioutil.ReadFile is compiled with the io/ioutil
> package.  It can't change based on how it is called.  So it is always
> going to return []byte.

Ok. I figured it might save an allocation as well if the coder made clear their
intention prior. I thought it may not be worth the effort, even if it were
straight forward.

Thanks for the consideration.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/30d863c3-c702-2f26-3b33-d66f4add4e40%40gmail.com.


Re: [go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Ian Lance Taylor
On Fri, Sep 11, 2020 at 9:45 AM Kevin Chadwick  wrote:
>
> I apologise if this has already been discussed. Google didn't turn up anything
> directly related.
>
> If you read a file using the following that returns a byte slice.
>
> tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert")
> if err != nil {
>log.Fatal(err)
> }
> tlsCert = string(tlsCertb)
>
> Is there a way to get a string without the cast.
>
> Otherwise couldn't the language automatically return a string rather than a 
> byte
> slice in these cases if the receiving var is already a string?
>
> e.g.
>
> var string tlsCert
> tlsCert, err = ioutil.ReadFile("/etc/ssl/mycert")
> if err != nil {
>log.Fatal(err)
> }

The way Go works, ioutil.ReadFile is compiled with the io/ioutil
package.  It can't change based on how it is called.  So it is always
going to return []byte.

The only way to implement what you suggest would be to add an implicit
conversion from []byte to string.  But that seems problematic.  In
general Go avoids implicit conversions except to interface types.  And
a conversion to string does require a copy, so it doesn't seem like a
great idea to do that implicitly.

If this happens a lot in your code, it seems easy enough to use a tiny
helper function.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcXD9ao9g3_B3zEnaZeRLkYHPjHYWHasWPUXb6ozNA1k0g%40mail.gmail.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Robert Engels
Please read golang.org/cmd/trace

You need a trace file. There are many ways to capture one. 

> On Sep 11, 2020, at 12:09 PM, Siddhesh Divekar  
> wrote:
> 
> 
> Ok, let me get them working first.
> 
> My concern with pprof is it has to be made part of my process.
> We had an issue where user requests were not reaching our http server itself.
> 
> In this case what are my options if pprof server is not reachable when we hit 
> the same issue again.
> Are there any other tools which can be run independently?
> 
>> On Fri, Sep 11, 2020 at 5:20 AM Robert Engels  wrote:
>> I would start with making sure you can get the standard ‘go tool trace’ and 
>> ‘pprof’ working. Once you have those working ‘goanalyzer’ is an enhanced 
>> version. 
>> 
>> The docs are far more complete and substantial on the standard tools. 
>> 
 On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar  
 wrote:
 
>>> 
>>> Is there any dependency on GOPATH while running `./goanalyzer binary 
>>> trace-file` ?
>>> Also my goanalyzer is built on mac and am trying to look at trace file 
>>> generated on ubuntu (shouldn't be a problem).
>>> 
>>> ./goanalyzer ~/workspace/binary  ~/workspace/trace
>>> 2020/09/10 23:27:32 Parsing trace...
>>> 2020/09/10 23:27:32 Splitting trace...
>>> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on 
>>> http://127.0.0.1:55520
>>> 
>>> If I try to go to a particular go routing eg 
>>> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
>>> 
>>> Clicking on any of the graphs for a goroutine says the following.
>>> failed to execute go tool pprof: exit status 1
>>> failed to execute dot. Is Graphviz installed? Error: exec: "dot": 
>>> executable file not found in $PATH
>>> 
 On Thu, Sep 10, 2020 at 4:49 PM robert engels  
 wrote:
 goanalyzer = go tool trace
 
 The options to goanalyzer are the same as ‘go tool trace’ - the usage 
 message is misleading in this way.
 
 By ‘map’ I mean expose the pprof port as you would any other port, and yes 
 you use the net/http/pprof to start the internal webserver - you don’t 
 need to create your own.
 
 
 
> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar 
>  wrote:
> 
> Hi Robert,
> 
> Laying down the steps to make sure I understood it correctly.
> 
>> You can map the port 
> What did you mean by above ? 
> 
>> but might be easier to capture to a file via code and use goanalyzer on 
>> the file
> In this case I will do the following.
> a) Set up a webserver in my program for getting Go profiles (with import 
> _ "net/http/pprof")
> b) map a port from outside k8s so that i can run curl 
> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say 
> profile-file)
> c) Use go tool pprof/goanalyzer to analyze given profile from the 
> profile-file
> 
> I would prefer to run this outside my process as the issue we expect to 
> happen is when my program is hung.
> I am not sure if the http server would respond & generate profile files.
> 
> From the help of goanalyzer it's not very clear how I would pass the 
> profile-file to it.
> It's showing how to generate profile-file using go test/tool but not how 
> to pass them to goanalyzer.
> 
> # ./goanalyzer -h
> Usage of 'go tool trace':
> Given a trace file produced by 'go test':
> go test -trace=trace.out pkg
> 
> Open a web browser displaying trace:
> go tool trace [flags] [pkg.test] trace.out
> 
> Generate a pprof-like profile from the trace:
> go tool trace -pprof=TYPE [pkg.test] trace.out
> 
> [pkg.test] argument is required for traces produced by Go 1.6 and below.
> Go 1.7 does not require the binary argument.
> 
> Supported profile types are:
> - net: network blocking profile
> - sync: synchronization blocking profile
> - syscall: syscall blocking profile
> - sched: scheduler latency profile
> 
> Flags:
> -http=addr: HTTP service address (e.g., ':6060')
> -pprof=type: print a pprof-like profile instead
> -d: print debug info such as parsed events
>  
> 
>> On Thu, Sep 10, 2020 at 3:22 PM Robert Engels  
>> wrote:
>> You can map the port but might be easier to capture to a file via code 
>> and use goanalyzer on the file. 
>> 
 On Sep 10, 2020, at 4:53 PM, Siddhesh Divekar 
  wrote:
 
>>> 
>>> Hi,
>>> 
>>> Has anyone tried running goanalyzer on golang process running inside 
>>> k8s pod.
>>> 
>>> If so can you point me to the steps.
>>> 
>>> -- 
>>> -Siddhesh.
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to 

Re: [go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Stephan Lukits


On Friday, 11 September 2020 at 21:04:11 UTC+3 mar...@gmail.com wrote:

> Which sqlite driver are you using? That sounds like a bug.
>

"github.com/mattn/go-sqlite3"
 

>
> On Fri, Sep 11, 2020 at 10:56 AM Stephan Lukits wrote:
>
>> I passed a string-type pointer (as last destination) to a sql.DB.Query 
>> call which had a NULL value as field value. No error was returned
>
>
Here I was wrong.  The error is returned by the Scan(...)-call (which I 
didn't catch, these are my first steps with go ...)
The reason why I was fixated on the Query-call was the way I tracked the 
cause:
I printed the functioning and not functioning DB-connection and saw that 
they differ
&{0 {:memory: 0xc0e0e0} 0 {0 0} [0xc000126a20] ...
&{0 {:memory: 0xc0e0e0} 0 {0 0} [] ...
at the slice. Pinging the non-functioning DB-connection put a new addres 
into the empty slice, so I assumed that this slice holds the open 
connections.
Then I narroed the two lines until I found the line where the switch to the 
empty slice happand which was oddly the Query-call.

The Questions which remain are, dose this connection gets closed allways 
when an error appears? Is it a bug? 
Can I use the API to figure if this connection was closed? Ping doesn't 
work because it just creates a new connection and pretends everything is 
fine.
My settings are:
.SetMaxOpenConns(1)
.SetConnMaxLifetime(0)
.SetConnMaxIdleTime(0)
(because I really don't want this connection to close ;)
 
Thanks Stephan

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3037ee1f-7fb5-4a24-a53a-2f64fdf976a3n%40googlegroups.com.


[go-nuts] Re: Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Volker Dobler
Please no. This is just begging for problems.
A simple type conversion is 1 (one!) line and pretty clear.
Once you open this can of worms someone would like
to  have a []rune and then automatic conversions from
int32 to int and 6 month later you have a JavaScript
like nonsense language just because you saved one
trivial line of code.

V

On Friday, 11 September 2020 at 18:45:52 UTC+2 m8il...@gmail.com wrote:

> I apologise if this has already been discussed. Google didn't turn up 
> anything
> directly related.
>
> If you read a file using the following that returns a byte slice.
>
> tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert")
> if err != nil {
> log.Fatal(err)
> }
> tlsCert = string(tlsCertb)
>
> Is there a way to get a string without the cast.
>
> Otherwise couldn't the language automatically return a string rather than 
> a byte
> slice in these cases if the receiving var is already a string?
>
> e.g.
>
> var string tlsCert
> tlsCert, err = ioutil.ReadFile("/etc/ssl/mycert")
> if err != nil {
> log.Fatal(err)
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/493ceb14-e34d-4c39-8d03-1c0c2c0358can%40googlegroups.com.


Re: [go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Marcin Romaszewicz
Which sqlite driver are you using? That sounds like a bug.

On Fri, Sep 11, 2020 at 10:56 AM Stephan Lukits 
wrote:

> I passed a string-type pointer (as last destination) to a sql.DB.Query
> call which had a NULL value as field value. No error was returned and all
> other fields got the appropriate values but the connection was silently
> closed.  I noticed because it was an in-memory (sqlite3) database which all
> of a sudden appeard empty.
>
> I could fix the problem for me by passing a sql.NullString instead of a
> string destination.  Maybe its interesting to know.
>
> Kind regards Stephan
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f639a2d4-46c0-4798-8be4-6fddd198ac5an%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2Bv29LvxwQUXZywLwpABQucvixVrDSdxvBDMLbnQrj%3DXOcOWVQ%40mail.gmail.com.


[go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Stephan Lukits
I passed a string-type pointer (as last destination) to a sql.DB.Query call 
which had a NULL value as field value. No error was returned and all other 
fields got the appropriate values but the connection was silently closed. 
 I noticed because it was an in-memory (sqlite3) database which all of a 
sudden appeard empty.

I could fix the problem for me by passing a sql.NullString instead of a 
string destination.  Maybe its interesting to know.

Kind regards Stephan 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f639a2d4-46c0-4798-8be4-6fddd198ac5an%40googlegroups.com.


[go-nuts] Q about memory allocation/cleanup with interfaces

2020-09-11 Thread Christopher Crotty
Apologies in advance if this is not the right group to post this...

I am having a memory leak issue in an app that reads data reports from a 
sensor and stores them for a length of time.  Running pprof on the app, It 
appears that the memory is not getting released when the old data is 
purged.  

There can be several report types, so I created an interface definition and 
am storing these reports under a slice of interfaces in a map with a 
timestamp key

When it comes time to purge, I'm setting the slice at that timestamp to 
nil, but the memory does not seem to be reclaimed.

Dirty Details:
The data comes in as a string message which I unmarshal into one of the 
concrete report types.  The reports are stored in the following structure...
map[string]map[int64][]ReportIface  where the first map has a key of 
sensorID and the inner map has a key of timestamp.  The ReportIface is an 
interface definition that all of the reports implement

During purging, I roll through the inner map and if the timestamp key is 
less than the purge time I  run the following
if reports[timestamp] != nil {
  reports[timestamp] = nil
}
delete(reports, timestamp).

Is there anything else I need to do for this?   Pprof is showing the memory 
from the unmarshal as still in use even after the purge.

Thanks in advance,
Chris

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d0a1eee7-7968-4560-9cd4-98d69e48ea91n%40googlegroups.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
Ok, let me get them working first.

My concern with pprof is it has to be made part of my process.
We had an issue where user requests were not reaching our http server
itself.

In this case what are my options if pprof server is not reachable when we
hit the same issue again.
Are there any other tools which can be run independently?

On Fri, Sep 11, 2020 at 5:20 AM Robert Engels  wrote:

> I would start with making sure you can get the standard ‘go tool trace’
> and ‘pprof’ working. Once you have those working ‘goanalyzer’ is an
> enhanced version.
>
> The docs are far more complete and substantial on the standard tools.
>
> On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar 
> wrote:
>
> 
> Is there any dependency on GOPATH while running `./goanalyzer binary
> trace-file` ?
> Also my goanalyzer is built on mac and am trying to look at trace file
> generated on ubuntu (shouldn't be a problem).
>
> ./goanalyzer ~/workspace/binary  ~/workspace/trace
> 2020/09/10 23:27:32 Parsing trace...
> 2020/09/10 23:27:32 Splitting trace...
> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on
> http://127.0.0.1:55520
>
> If I try to go to a particular go routing eg
> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
>
> Clicking on any of the graphs for a goroutine says the following.
>
> failed to execute go tool pprof: exit status 1
> failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable 
> file not found in $PATH
>
>
> On Thu, Sep 10, 2020 at 4:49 PM robert engels 
> wrote:
>
>> goanalyzer = go tool trace
>>
>> The options to goanalyzer are the same as ‘go tool trace’ - the usage
>> message is misleading in this way.
>>
>> By ‘map’ I mean expose the pprof port as you would any other port, and
>> yes you use the net/http/pprof to start the internal webserver - you don’t
>> need to create your own.
>>
>>
>>
>> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar 
>> wrote:
>>
>> Hi Robert,
>>
>> Laying down the steps to make sure I understood it correctly.
>>
>> You can map the port
>>>
>> What did you mean by above ?
>>
>> but might be easier to capture to a file via code and use goanalyzer on
>>> the file
>>>
>> In this case I will do the following.
>> a) Set up a webserver in my program for getting Go profiles (with import
>> _ "net/http/pprof")
>> b) map a port from outside k8s so that i can run curl
>> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say
>> profile-file)
>> c) Use go tool pprof/goanalyzer to analyze given profile from the
>> profile-file
>>
>> I would prefer to run this outside my process as the issue we expect to
>> happen is when my program is hung.
>> I am not sure if the http server would respond & generate profile files.
>>
>> From the help of goanalyzer it's not very clear how I would pass the
>> profile-file to it.
>> It's showing how to generate profile-file using go test/tool but not how
>> to pass them to goanalyzer.
>>
>> # ./goanalyzer -h
>> Usage of 'go tool trace':
>> Given a trace file produced by 'go test':
>> go test -trace=trace.out pkg
>>
>> Open a web browser displaying trace:
>> go tool trace [flags] [pkg.test] trace.out
>>
>> Generate a pprof-like profile from the trace:
>> go tool trace -pprof=TYPE [pkg.test] trace.out
>>
>> [pkg.test] argument is required for traces produced by Go 1.6 and below.
>> Go 1.7 does not require the binary argument.
>>
>> Supported profile types are:
>> - net: network blocking profile
>> - sync: synchronization blocking profile
>> - syscall: syscall blocking profile
>> - sched: scheduler latency profile
>>
>> Flags:
>> -http=addr: HTTP service address (e.g., ':6060')
>> -pprof=type: print a pprof-like profile instead
>> -d: print debug info such as parsed events
>>
>>
>> On Thu, Sep 10, 2020 at 3:22 PM Robert Engels 
>> wrote:
>>
>>> You can map the port but might be easier to capture to a file via code
>>> and use goanalyzer on the file.
>>>
>>> On Sep 10, 2020, at 4:53 PM, Siddhesh Divekar <
>>> siddhesh.dive...@gmail.com> wrote:
>>>
>>> 
>>> Hi,
>>>
>>> Has anyone tried running goanalyzer on golang process running inside k8s
>>> pod.
>>>
>>> If so can you point me to the steps.
>>>
>>> --
>>> -Siddhesh.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/CAMjfk%2BhUDqMRmE0mDp_gMTKWKT0Be8KgtBxuF2fYAGCs-dNoog%40mail.gmail.com
>>> 
>>> .
>>>
>>>
>>
>> --
>> -Siddhesh.
>>
>>
>>
>
> --
> -Siddhesh.
>
>

-- 
-Siddhesh.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from 

[go-nuts] Proposal: auto return String instead of []byte if requested

2020-09-11 Thread Kevin Chadwick
I apologise if this has already been discussed. Google didn't turn up anything
directly related.

If you read a file using the following that returns a byte slice.

tlsCertb, err := ioutil.ReadFile("/etc/ssl/mycert")
if err != nil {
   log.Fatal(err)
}
tlsCert = string(tlsCertb)

Is there a way to get a string without the cast.

Otherwise couldn't the language automatically return a string rather than a byte
slice in these cases if the receiving var is already a string?

e.g.

var string tlsCert
tlsCert, err = ioutil.ReadFile("/etc/ssl/mycert")
if err != nil {
   log.Fatal(err)
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/80be59d6-be0a-4112-3c6b-7f37b05543ea%40gmail.com.


Re: [go-nuts] zombie parent scenario with golang

2020-09-11 Thread Uday Kiran Jonnala
Hi  Kurtis,

Thanks for the reply. I was giving C code to show the behavior of defunct 
with threads still executing in a process. I do feel defunct process should 
not have any associated resources or threads held.
Could be an issue with this Linux version, will check on the behavior in 
Linux community why defunct still showing threads with resources.

I was giving this C example to check if the go process may be hitting into 
the same situation.

Thanks again for the time. 

Thanks & Regards,
Uday Kiran 

On Thursday, September 10, 2020 at 11:00:57 PM UTC-7 ba...@iitbombay.org 
wrote:

> 1. Looks like*something* in ps reports process/thread state incorrectly. 
> It should not report  until all the pthreads have exited and the 
> parent has not picked up the status. The runtime will call exit() when the 
> last thread terminates (exit() in turn will call the _exit syscall).
>
> 2. If any thread calls _exit(), the system will clean up everything. It 
> doesn't matter how many threads may  be active. You can see this for 
> yourself if you replaced pthread_exit() in main() with _exit(0).
>
> 3. stacktrace within the kernel mode is irrelevant. You are merely 
> confusing yourself.
>
> 4. Go runtime doesn't use pthread so not sure testing pthread based C 
> program is relevant. Exiting from func main() will kill all goroutines. 
> Copy https://play.golang.org/p/zRfhvfYt_oE locally and see for yourself.
>
> 5. Looking at your original message, it *seems* like a parent is not 
> picking up the child's status. But I can't be sure.
>
> I suspect you are on a wild goose chase. Possibly confused by ps. You may 
> wish to backtrack to whatever you were looking at before this  
> came up. Or try explaining what is going on with your go program and what 
> you expect it should do, without stacktrace or C programs etc.
>
> I wouldn't switch to a newer kernel if I were you. When debugging you 
> should keep everything else fixed or else you may end up chasing something 
> different or the symptom may change or disappear.
>
> On Sep 10, 2020, at 10:08 PM, Uday Kiran Jonnala  
> wrote:
>
> Thanks Kurtis for the reply. I understand defunct process mechanism. 
>
> As I mentioned in the initial mail, [Correct me if I am wrong here], In a 
> process if there is main thread and a detached thread created by main 
> thread, when the main thread exits the process is kept in defunct state, 
> since the created thread is still
> executing, I was thinking if we have such scenario in go runtime. That 
> could be the reason I see this thread is waiting on futex and holding the 
> file handles and causing the go process (kernel) not to send SIGCHLD to 
> parent process.
>
> For example below case
>
> #include 
> #include 
> #include 
> #include 
>
> void *thread_function(void *args)
> {
> printf("The is new thread! Sleep 20 seconds...\n");
> sleep(100);
> printf("Exit from thread\n");
> pthread_exit(0);
> }
>
> int main(int argc, char **argv)
> {
>  pthread_t thrd;
>  pthread_attr_t attr;
>  int res = 0;
>  res = pthread_attr_init();
>  res = pthread_attr_setdetachstate(, PTHREAD_CREATE_DETACHED);
>  res = pthread_create(, , thread_function, NULL);
>  res = pthread_attr_destroy();
>  printf("Main thread. Sleep 5 seconds\n");
>  sleep(5);
>  printf("Exit from main process\n");
>  pthread_exit(0);
> }
>
> ujonnala@ ~/mycode/go () $ ps -T
>PID   SPID TTY  TIME CMD
>  43635  43635 pts/29   00:00:00 a.out 
>  43635  43638 pts/29   00:00:00 a.out
>
> Due to the detached thread still executing the process left in defunt 
> state. 
>
> Thanks for checking on this, I will see if we can reproduce my situation 
> on a newer kernel.
>
> Thanks & Regards,
> Uday Kiran
>
> On Thursday, September 10, 2020 at 9:49:06 PM UTC-7 Kurtis Rader wrote:
>
>> On Thu, Sep 10, 2020 at 9:25 PM Uday Kiran Jonnala  
>> wrote:
>>
>>> Thanks for the reply. We are fixing the issue. But the point I wanted to 
>>> bring it up here is the issue of a thread causing the go process to be in 
>>> defunct state.
>>>
>>
>> Any thread can cause the go process to enter the "defunct" state. For 
>> example, by calling os.Exit(), or panic(), or causing a signal to be 
>> delivered that terminates the process (e.g., SIGSEGV).
>>  
>>
>>> My kernel version is 
>>> Linux version 4.14.175-1.nutanix.20200709.el7.x86_64 (dev@ca4b0551898c) 
>>> (gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)) #1 SMP Fri Jul 10 
>>> 02:17:54 UTC 2020
>>>
>>
>> Is that the output of `uname -a`? It seems to suggest you're using CentOS 
>> provided by the https://www.nutanix.com/go/linux-on-ahv cloud 
>> environment. So we've established you are using Linux with kernel version 
>> 4.14. A kernel that is now three years old. I don't have anything like it 
>> installed on any of my virtual machines so I can't explore how it handles 
>> defunct processes. But my prior point stands: A "defunct" process is one 
>> that has been terminated but whose parent process has not reaped its exit 
>> 

Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Robert Engels
I would start with making sure you can get the standard ‘go tool trace’ and 
‘pprof’ working. Once you have those working ‘goanalyzer’ is an enhanced 
version. 

The docs are far more complete and substantial on the standard tools. 

> On Sep 11, 2020, at 1:37 AM, Siddhesh Divekar  
> wrote:
> 
> 
> Is there any dependency on GOPATH while running `./goanalyzer binary 
> trace-file` ?
> Also my goanalyzer is built on mac and am trying to look at trace file 
> generated on ubuntu (shouldn't be a problem).
> 
> ./goanalyzer ~/workspace/binary  ~/workspace/trace
> 2020/09/10 23:27:32 Parsing trace...
> 2020/09/10 23:27:32 Splitting trace...
> 2020/09/10 23:27:32 Opening browser. Trace viewer is listening on 
> http://127.0.0.1:55520
> 
> If I try to go to a particular go routing eg 
> http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.
> 
> Clicking on any of the graphs for a goroutine says the following.
> failed to execute go tool pprof: exit status 1
> failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable 
> file not found in $PATH
> 
>> On Thu, Sep 10, 2020 at 4:49 PM robert engels  wrote:
>> goanalyzer = go tool trace
>> 
>> The options to goanalyzer are the same as ‘go tool trace’ - the usage 
>> message is misleading in this way.
>> 
>> By ‘map’ I mean expose the pprof port as you would any other port, and yes 
>> you use the net/http/pprof to start the internal webserver - you don’t need 
>> to create your own.
>> 
>> 
>> 
>>> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar  
>>> wrote:
>>> 
>>> Hi Robert,
>>> 
>>> Laying down the steps to make sure I understood it correctly.
>>> 
 You can map the port 
>>> What did you mean by above ? 
>>> 
 but might be easier to capture to a file via code and use goanalyzer on 
 the file
>>> In this case I will do the following.
>>> a) Set up a webserver in my program for getting Go profiles (with import _ 
>>> "net/http/pprof")
>>> b) map a port from outside k8s so that i can run curl 
>>> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say 
>>> profile-file)
>>> c) Use go tool pprof/goanalyzer to analyze given profile from the 
>>> profile-file
>>> 
>>> I would prefer to run this outside my process as the issue we expect to 
>>> happen is when my program is hung.
>>> I am not sure if the http server would respond & generate profile files.
>>> 
>>> From the help of goanalyzer it's not very clear how I would pass the 
>>> profile-file to it.
>>> It's showing how to generate profile-file using go test/tool but not how to 
>>> pass them to goanalyzer.
>>> 
>>> # ./goanalyzer -h
>>> Usage of 'go tool trace':
>>> Given a trace file produced by 'go test':
>>> go test -trace=trace.out pkg
>>> 
>>> Open a web browser displaying trace:
>>> go tool trace [flags] [pkg.test] trace.out
>>> 
>>> Generate a pprof-like profile from the trace:
>>> go tool trace -pprof=TYPE [pkg.test] trace.out
>>> 
>>> [pkg.test] argument is required for traces produced by Go 1.6 and below.
>>> Go 1.7 does not require the binary argument.
>>> 
>>> Supported profile types are:
>>> - net: network blocking profile
>>> - sync: synchronization blocking profile
>>> - syscall: syscall blocking profile
>>> - sched: scheduler latency profile
>>> 
>>> Flags:
>>> -http=addr: HTTP service address (e.g., ':6060')
>>> -pprof=type: print a pprof-like profile instead
>>> -d: print debug info such as parsed events
>>>  
>>> 
 On Thu, Sep 10, 2020 at 3:22 PM Robert Engels  
 wrote:
 You can map the port but might be easier to capture to a file via code and 
 use goanalyzer on the file. 
 
>> On Sep 10, 2020, at 4:53 PM, Siddhesh Divekar 
>>  wrote:
>> 
> 
> Hi,
> 
> Has anyone tried running goanalyzer on golang process running inside k8s 
> pod.
> 
> If so can you point me to the steps.
> 
> -- 
> -Siddhesh.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/CAMjfk%2BhUDqMRmE0mDp_gMTKWKT0Be8KgtBxuF2fYAGCs-dNoog%40mail.gmail.com.
>>> 
>>> 
>>> -- 
>>> -Siddhesh.
>> 
> 
> 
> -- 
> -Siddhesh.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/E4022F98-1D2D-4D03-A070-4FAF861EF5C3%40ix.netcom.com.


Re: [go-nuts] unit test for function which has goroutine

2020-09-11 Thread roger peppe
On Thu, 10 Sep 2020 at 08:15, Yvonne Zhang  wrote:

> Hi,
> I have a function streaming a zipreader to browser. It is like this.
> func functionA()(body io.ReadCloser, err error){
>
>// some logic to get a zipreader
>
>body, pipeWriter := io.Pipe()
>zipWriter := zip.NewWriter(pipeWriter)
>
>go func(){
>   // err := functionB(zipReader, zipWriter)call another function to
> prepare files and write to zipwriter
>If err != nil{
>zipWriter.Close()
> _ = pipeWriter.CloseWithError(err)
> return
>}
>   zipWriter.Close()
>pipeWriter.Close()
>}()
>return
> }
>
> My question is about unit test about this functionA. I have mock for
> functionB. How do I write unit test for functionA with the mock functionB.
> It seems my unit test does not work well when it goes into the goroutine.
> Many thanks!
>

For the record, my usual response to this, assuming that function A and
function B are not exported functions, is that you'd be better off not
writing unit tests for the individual functions, but testing (as far as
possible) against the publicly exported interface. I tend to think about
what the overall contract is (the contract that really matters from the
external consumer's point of view) and test that.

If you do that, then your tests will remain useful even if you decide to
refactor the code. That is a significant part of the value of automated
tests in my view.

In this particular case ISTM that the goroutine is just an implementation
detail. If you set up the stream source somehow, you could use the net/http
package to hit the endpoint that does the streaming and check that you're
seeing the correct result. Depending on what the source is, you *might* need
to fake it up somehow, but I'd always be inclined to use the lowest
available level to do that, so you're testing as much of the stack as you
can (and thus giving yourself most confidence in the code and most freedom
to refactor later).

I'm aware that in saying this, I'm going directly against unit-testing
advice available elsewhere. :) YMMV. And it's worth noting: when testing,
there are no absolutes and context is crucial for making a decision as to
what and how to test.

  hope this helps,
rog.


> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/4ca0817a-f1f7-44a9-be3d-3584bcb61b8an%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAJhgachcE4wpSos7rt8tELi0P3xwKyL-SKrbo6R%2BQSFbwDF2rw%40mail.gmail.com.


Re: [go-nuts] Running goanalyzer on golang process running inside kubernetes pod

2020-09-11 Thread Siddhesh Divekar
Is there any dependency on GOPATH while running `./goanalyzer binary
trace-file` ?
Also my goanalyzer is built on mac and am trying to look at trace file
generated on ubuntu (shouldn't be a problem).

./goanalyzer ~/workspace/binary  ~/workspace/trace
2020/09/10 23:27:32 Parsing trace...
2020/09/10 23:27:32 Splitting trace...
2020/09/10 23:27:32 Opening browser. Trace viewer is listening on
http://127.0.0.1:55520

If I try to go to a particular go routing eg
http://127.0.0.1:55520/trace?goid=9084 I see nothing on the browser.

Clicking on any of the graphs for a goroutine says the following.

failed to execute go tool pprof: exit status 1
failed to execute dot. Is Graphviz installed? Error: exec: "dot":
executable file not found in $PATH


On Thu, Sep 10, 2020 at 4:49 PM robert engels  wrote:

> goanalyzer = go tool trace
>
> The options to goanalyzer are the same as ‘go tool trace’ - the usage
> message is misleading in this way.
>
> By ‘map’ I mean expose the pprof port as you would any other port, and yes
> you use the net/http/pprof to start the internal webserver - you don’t need
> to create your own.
>
>
>
> On Sep 10, 2020, at 6:38 PM, Siddhesh Divekar 
> wrote:
>
> Hi Robert,
>
> Laying down the steps to make sure I understood it correctly.
>
> You can map the port
>>
> What did you mean by above ?
>
> but might be easier to capture to a file via code and use goanalyzer on
>> the file
>>
> In this case I will do the following.
> a) Set up a webserver in my program for getting Go profiles (with import _
> "net/http/pprof")
> b) map a port from outside k8s so that i can run curl
> localhost:$PORT/debug/pprof/$PROFILE_TYPE to save a profile (say
> profile-file)
> c) Use go tool pprof/goanalyzer to analyze given profile from the
> profile-file
>
> I would prefer to run this outside my process as the issue we expect to
> happen is when my program is hung.
> I am not sure if the http server would respond & generate profile files.
>
> From the help of goanalyzer it's not very clear how I would pass the
> profile-file to it.
> It's showing how to generate profile-file using go test/tool but not how
> to pass them to goanalyzer.
>
> # ./goanalyzer -h
> Usage of 'go tool trace':
> Given a trace file produced by 'go test':
> go test -trace=trace.out pkg
>
> Open a web browser displaying trace:
> go tool trace [flags] [pkg.test] trace.out
>
> Generate a pprof-like profile from the trace:
> go tool trace -pprof=TYPE [pkg.test] trace.out
>
> [pkg.test] argument is required for traces produced by Go 1.6 and below.
> Go 1.7 does not require the binary argument.
>
> Supported profile types are:
> - net: network blocking profile
> - sync: synchronization blocking profile
> - syscall: syscall blocking profile
> - sched: scheduler latency profile
>
> Flags:
> -http=addr: HTTP service address (e.g., ':6060')
> -pprof=type: print a pprof-like profile instead
> -d: print debug info such as parsed events
>
>
> On Thu, Sep 10, 2020 at 3:22 PM Robert Engels 
> wrote:
>
>> You can map the port but might be easier to capture to a file via code
>> and use goanalyzer on the file.
>>
>> On Sep 10, 2020, at 4:53 PM, Siddhesh Divekar 
>> wrote:
>>
>> 
>> Hi,
>>
>> Has anyone tried running goanalyzer on golang process running inside k8s
>> pod.
>>
>> If so can you point me to the steps.
>>
>> --
>> -Siddhesh.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to golang-nuts+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/CAMjfk%2BhUDqMRmE0mDp_gMTKWKT0Be8KgtBxuF2fYAGCs-dNoog%40mail.gmail.com
>> 
>> .
>>
>>
>
> --
> -Siddhesh.
>
>
>

-- 
-Siddhesh.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMjfk%2Bh%2BxrRr9PqoZEAsjv-QVJOi8pzP4gk7VUFfnfXw-Je51Q%40mail.gmail.com.


Re: [go-nuts] zombie parent scenario with golang

2020-09-11 Thread Bakul Shah
1. Looks like*something* in ps reports process/thread state incorrectly. It 
should not report  until all the pthreads have exited and the parent 
has not picked up the status. The runtime will call exit() when the last thread 
terminates (exit() in turn will call the _exit syscall).

2. If any thread calls _exit(), the system will clean up everything. It doesn't 
matter how many threads may  be active. You can see this for yourself if you 
replaced pthread_exit() in main() with _exit(0).

3. stacktrace within the kernel mode is irrelevant. You are merely confusing 
yourself.

4. Go runtime doesn't use pthread so not sure testing pthread based C program 
is relevant. Exiting from func main() will kill all goroutines. Copy 
https://play.golang.org/p/zRfhvfYt_oE locally and see for yourself.

5. Looking at your original message, it *seems* like a parent is not picking up 
the child's status. But I can't be sure.

I suspect you are on a wild goose chase. Possibly confused by ps. You may wish 
to backtrack to whatever you were looking at before this  came up. Or 
try explaining what is going on with your go program and what you expect it 
should do, without stacktrace or C programs etc.

I wouldn't switch to a newer kernel if I were you. When debugging you should 
keep everything else fixed or else you may end up chasing something different 
or the symptom may change or disappear.

> On Sep 10, 2020, at 10:08 PM, Uday Kiran Jonnala  wrote:
> 
> Thanks Kurtis for the reply. I understand defunct process mechanism. 
> 
> As I mentioned in the initial mail, [Correct me if I am wrong here], In a 
> process if there is main thread and a detached thread created by main thread, 
> when the main thread exits the process is kept in defunct state, since the 
> created thread is still
> executing, I was thinking if we have such scenario in go runtime. That could 
> be the reason I see this thread is waiting on futex and holding the file 
> handles and causing the go process (kernel) not to send SIGCHLD to parent 
> process.
> 
> For example below case
> 
> #include 
> #include 
> #include 
> #include 
> 
> void *thread_function(void *args)
> {
> printf("The is new thread! Sleep 20 seconds...\n");
> sleep(100);
> printf("Exit from thread\n");
> pthread_exit(0);
> }
> 
> int main(int argc, char **argv)
> {
>  pthread_t thrd;
>  pthread_attr_t attr;
>  int res = 0;
>  res = pthread_attr_init();
>  res = pthread_attr_setdetachstate(, PTHREAD_CREATE_DETACHED);
>  res = pthread_create(, , thread_function, NULL);
>  res = pthread_attr_destroy();
>  printf("Main thread. Sleep 5 seconds\n");
>  sleep(5);
>  printf("Exit from main process\n");
>  pthread_exit(0);
> }
> 
> ujonnala@ ~/mycode/go () $ ps -T
>PID   SPID TTY  TIME CMD
>  43635  43635 pts/29   00:00:00 a.out 
>  43635  43638 pts/29   00:00:00 a.out
> 
> Due to the detached thread still executing the process left in defunt state. 
> 
> Thanks for checking on this, I will see if we can reproduce my situation on a 
> newer kernel.
> 
> Thanks & Regards,
> Uday Kiran
> 
> On Thursday, September 10, 2020 at 9:49:06 PM UTC-7 Kurtis Rader wrote:
> On Thu, Sep 10, 2020 at 9:25 PM Uday Kiran Jonnala  > wrote:
> Thanks for the reply. We are fixing the issue. But the point I wanted to 
> bring it up here is the issue of a thread causing the go process to be in 
> defunct state.
> 
> Any thread can cause the go process to enter the "defunct" state. For 
> example, by calling os.Exit(), or panic(), or causing a signal to be 
> delivered that terminates the process (e.g., SIGSEGV).
>  
> My kernel version is 
> Linux version 4.14.175-1.nutanix.20200709.el7.x86_64 (dev@ca4b0551898c) (gcc 
> version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)) #1 SMP Fri Jul 10 02:17:54 
> UTC 2020
> 
> Is that the output of `uname -a`? It seems to suggest you're using CentOS 
> provided by the https://www.nutanix.com/go/linux-on-ahv 
>  cloud environment. So we've 
> established you are using Linux with kernel version 4.14. A kernel that is 
> now three years old. I don't have anything like it installed on any of my 
> virtual machines so I can't explore how it handles defunct processes. But my 
> prior point stands: A "defunct" process is one that has been terminated but 
> whose parent process has not reaped its exit status. Either that parent 
> process has a bug (the most likely explanation) or your OS has a bug.
> 
> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com 
> .
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/ad4843e1-f7d1-43ae-8091-579bc61527fdn%40googlegroups.com
>  
>