[go-nuts] channel synchronous, how to assure happens before ??
After reading blog post : https://golang.org/ref/mem I got one question, in the code below: var c = make(chan int, 10) var a string func f() { a = "hello, world" c <- 0 } func main() { go f() <-c print(a) } How can the complier knows that a = "hello, world" happens c <-0. Or could it possible that c <-0 happens first, a = "hello, world" happens second ?? -- 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/2257b529-ce46-4996-9497-c3190975c0c9%40googlegroups.com.
Re: [go-nuts] channel synchronous, how to assure happens before ??
thanks for your reply. Could you guide me any readings or source code about channel of happens before. On Tuesday, January 7, 2020 at 3:02:30 AM UTC+8, Ian Lance Taylor wrote: > > On Mon, Jan 6, 2020 at 10:55 AM hao dong > > wrote: > > > > After reading blog post : https://golang.org/ref/mem > > > > I got one question, in the code below: > > > > > > var c = make(chan int, 10) > > var a string > > > > func f() { > > a = "hello, world" > > c <- 0 > > } > > > > func main() { > > go f() > > <-c > > print(a) > > } > > > > > > How can the complier knows that a = "hello, world" happens c <-0. Or > could it possible that c <-0 happens first, a = "hello, world" happens > second ?? > > The compiler ensures that the assignment to a happens before the send > operation on c. > > If that doesn't answer your question, can you explain in more detail? > > 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/5283097c-e526-4e01-8174-449a8cf4e6e0%40googlegroups.com.
Re: [go-nuts] channel synchronous, how to assure happens before ??
Thank you for your reply, I agree there should be a memory barrier for the channel, for it is different from the other assignment statements and not a write operation. Have you got some readings talk about this? On Tuesday, January 7, 2020 at 10:17:43 AM UTC+8, Kurtis Rader wrote: > > On Mon, Jan 6, 2020 at 5:47 PM hao dong > > wrote: > >> thanks for your reply. Could you guide me any readings or source code >> about channel of happens before. >> > > I think you have misunderstood this text in the https://golang.org/ref/mem > document you linked to: > > Within a single goroutine, reads and writes must behave as if they >> executed in the order specified by the program. That is, compilers and >> processors may reorder the reads and writes executed within a single >> goroutine only when the reordering does not change the behavior within that >> goroutine as defined by the language specification. Because of this >> reordering, the execution order observed by one goroutine may differ from >> the order perceived by another. > > > The send on the channel is not a "write" operation in the sense meant by > the above text. Nor is the receive on the channel a "read" operation. That > paragraph is talking about reads and writes of memory in units (bytes, > words, etc.) supported by the CPU. Also, notice the "only when the > reordering does not change the behavior" portion of the above text. If the > compiler did the assignment after the send on the channel that would change > the behavior of the program. Channel ops are what are known as memory > barriers, and thus don't allow ops before or after the channel op to be > reordered before or after the op. > > -- > 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/37c57f74-f736-4b12-bbb4-ddbac172ec74%40googlegroups.com.
[go-nuts] Re: Is there a way to limit number or requests on a KeepAlive connection on net/http server?
I don't think you can limit the number of requests by the *MaxRequestsPerConn* of fasthttp, because the Conn in this func is new struct created by fasthttp which stores in pool. Real client connections will be send to channels which be processed by these Conns. For @ Tamás , Server.ConnState applies to net connections, not request on the keep-live connection. On Monday, January 13, 2020 at 3:00:10 PM UTC+8, zohaib...@doordash.com wrote: > > Hey folks, > > I've been digging around for a while but could not find anything; is > there something with builtin HTTP server that I can do to limit the maximum > number of requests allowed with KeepAlive connection? I found fast http > provides an option *MaxRequestsPerConn* to do so, > https://github.com/valyala/fasthttp/blob/59b28fe0e54664073ac4e422511ca8af718b26b0/server.go#L233-L239 > is > there something out of the box too? If not I really want to stick to stock > net/http package; is there a quick cheap way to do that? > -- 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/05a4ceba-5ed0-4be7-8c3c-3e2544c63ccb%40googlegroups.com.
[go-nuts] Re: Reusing tcp connections on tunnels
I don't think every net.Dial() creates an actually tcp connection to a server, this func is just an abstract of system call. Desingers of Go are so clever that will not do this stupid thing. I think I will make a test of that. On Friday, January 17, 2020 at 4:07:28 AM UTC+8, XXX ZZZ wrote: > > Hello, > > I'm trying to write an application that will basically serve as a tunnel > between some servers outside our network and our internal servers. For this > I've started using a snippet that creates a tcp listener and then dials to > a remote host. Code is shown here: > > https://play.golang.org/p/4wjCZFXq6Yg > > The code works just fine, however every time it gets a new request it > dials a new connection to the remote host, and then after all data has been > forwarded to both sides it closes them. I'm no expert on networking but > this looks like its just opening/closing tcp connections instead of just > reusing them, is this correct? if so, what would be the correct way of > resuing the connection? > > Thanks! > -- 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/c3f42f36-7eb5-4e0a-9426-d79a805c9da8%40googlegroups.com.
[go-nuts] where is temp file created by http server
As I have learned, http server will store user-upload file on disk when its size exceed 32MB. I read the source code, and find out the large file to store in os.TempDir(), however, after uploading a large file, I can not find the file in the temp dir. Cloud someone enlight me, where is the temp file ? -- 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/0232db86-9bfb-42ae-b24b-49ea57a222ado%40googlegroups.com.
Re: [go-nuts] where is temp file created by http server
thx. Can you help me find the link or doc which describe the detail of " removed once the request finished" ? On Thursday, July 16, 2020 at 7:32:06 PM UTC+8, Jesper Louis Andersen wrote: > > They will be removed once the request finishes. The way to access them is > usually by the FormFile method on *http.Request or to create a multipart > reader and break it out yourself. > > The reason the latter is interesting is because it can avoid storing data > you are not prepared to handle. > > On Thu, Jul 16, 2020 at 12:44 PM hao dong > > wrote: > >> As I have learned, http server will store user-upload file on disk when >> its size exceed 32MB. >> I read the source code, and find out the large file to store in >> os.TempDir(), however, after uploading a large file, I can not find the >> file in the temp dir. >> Cloud someone enlight me, where is the temp file ? >> >> -- >> 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 golan...@googlegroups.com . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/0232db86-9bfb-42ae-b24b-49ea57a222ado%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/0232db86-9bfb-42ae-b24b-49ea57a222ado%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > > > -- > J. > -- 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/53d14db3-1c23-43f0-9613-1c7ac7645e96o%40googlegroups.com.
Re: [go-nuts] where is temp file created by http server
thanks. I've noticed the code,too. And that's what I'm confused: when there is a create, there is no delete, and I can not find the file under os.TemDir() Seems I have to debug the code to find the removing line. On Friday, July 17, 2020 at 9:06:22 AM UTC+8, Jonathan Reiter wrote: > > See the multipart function definition. Line 86 deals with the actual temp > file writes. > > https://golang.org/src/mime/multipart/formdata.go?s=3015:3047#L34 > > Do note that under certain conditions, a multipart form might hold on > closing and deleting the multipart files in temp. Debugging async code and > judicious use of RemoveAll can help with this. > > https://golang.org/pkg/mime/multipart/#Form.RemoveAll > > > > On Thu, Jul 16, 2020 at 5:59 PM hao dong > > wrote: > >> thx. Can you help me find the link or doc which describe the detail of " >> removed once the request finished" ? >> >> On Thursday, July 16, 2020 at 7:32:06 PM UTC+8, Jesper Louis Andersen >> wrote: >>> >>> They will be removed once the request finishes. The way to access them >>> is usually by the FormFile method on *http.Request or to create a multipart >>> reader and break it out yourself. >>> >>> The reason the latter is interesting is because it can avoid storing >>> data you are not prepared to handle. >>> >>> On Thu, Jul 16, 2020 at 12:44 PM hao dong wrote: >>> >>>> As I have learned, http server will store user-upload file on disk when >>>> its size exceed 32MB. >>>> I read the source code, and find out the large file to store in >>>> os.TempDir(), however, after uploading a large file, I can not find the >>>> file in the temp dir. >>>> Cloud someone enlight me, where is the temp file ? >>>> >>>> -- >>>> 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 golan...@googlegroups.com. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/golang-nuts/0232db86-9bfb-42ae-b24b-49ea57a222ado%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/golang-nuts/0232db86-9bfb-42ae-b24b-49ea57a222ado%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> >>> >>> >>> -- >>> J. >>> >> -- >> 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 golan...@googlegroups.com . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/53d14db3-1c23-43f0-9613-1c7ac7645e96o%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/53d14db3-1c23-43f0-9613-1c7ac7645e96o%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- 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/ae4c2ef0-a487-4dcd-9cbd-ff01558f5f9ao%40googlegroups.com.
Re: [go-nuts] where is temp file created by http server
thx. I'll check it. On Saturday, July 18, 2020 at 12:03:52 AM UTC+8, Jake Montgomery wrote: > > On Thursday, July 16, 2020 at 10:32:32 PM UTC-4, hao dong wrote: >> >> thanks. I've noticed the code,too. And that's what I'm confused: when >> there is a create, there is no delete, and I can not find the file under >> os.TemDir() >> Seems I have to debug the code to find the removing line. >> > > I believe the delete happens at the end of finishRequest: > https://golang.org/src/net/http/server.go#L1612 > > if w.req.MultipartForm != nil { > > w.req.MultipartForm.RemoveAll() > > } > > > Not verified, but that looks like it. > >> -- 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/0905a00b-9919-43b6-8e5d-f325fab3d782o%40googlegroups.com.