logo
down
shadow

Invalid Read on closed Body on Google App Engine


Invalid Read on closed Body on Google App Engine

By : Timothy
Date : November 22 2020, 07:01 PM
will be helpful for those in need By design, the HTTP/1.x server in Go closes the *http.Request.Body after the first flush of the http.ResponseWriter. See this GitHub issue for the explanation.
Concurrently reading and writing is fine in theory — it’s unspecified from a standards perspective — but Go does not handle it. If code begins writing to the Response before the Body is completely consumed, there is a good chance that the Body will be closed unexpectedly.
code :


Share : facebook icon twitter icon
Data Read Returning (Invalid Attempt to Read when Reader is closed)

Data Read Returning (Invalid Attempt to Read when Reader is closed)


By : Fly
Date : March 29 2020, 07:55 AM
wish help you to fix your issue It may have something to do with the fact that the first ittereation would be reader[0] but surely the second itteration will be reader[1], therefore you want to use
code :
 reader.GetString(0)
 reader[0].ToString();
Invalid attempt to Read when reader is closed

Invalid attempt to Read when reader is closed


By : Ralph.Emerson
Date : March 29 2020, 07:55 AM
To fix this issue You can load the results of your query to memory, then close the connection and still return an IDataReader that works as expected. Note that this costs memory.
code :
public IDataReader getRecord(string query)
    {
        MySqlDataReader reader;
        using (var connection = new MySqlConnection(connectionString))
        {
            connection.Open();
            using (var cmd = new MySqlCommand(query, connection))
            {

                reader = cmd.ExecuteReader();
                var dt = new DataTable();
                dt.Load( reader );
                return dt.CreateDataReader();
            }
        }

        return null;
    }
String sql = "SELECT * FROM `table`";
var dr = objDB.getRecord(sql); // or DataTableReader dr = ...
if (dr.Read())
{
    // some code goes here
} 
HTTP ERROR: 503 Google App Engine - Closed

HTTP ERROR: 503 Google App Engine - Closed


By : marjon8888
Date : March 29 2020, 07:55 AM
I hope this helps you . Okay, I solved this by dectuple checking my web.xml. I had a typo and broke the whole app.
My package was starting with a Capital Letter in the web.xml, which should not.
Some google compute engine ports are closed

Some google compute engine ports are closed


By : Moin
Date : March 29 2020, 07:55 AM
this will help After an hour this mysteriously became unblocked. I was using the same port tester each time.
http://www.yougetsignal.com/tools/open-ports/
Go keep get scan file error: http: invalid Read on closed Body

Go keep get scan file error: http: invalid Read on closed Body


By : AndyLee
Date : March 29 2020, 07:55 AM
Hope that helps Looks like your server is closing the connection. Check for any timeouts you have and why the request takes so long. You could process the scanner.Text() asynchronously so your scanning is not blocked for the searchAPI to respond, and the request body is not open for too long.
code :
    resp.Header().Set("Content-Type", "text/plain")
    scanner := bufio.NewScanner(req.Body)

    ctx := context.Background()
    for scanner.Scan() {
        itemID := scanner.Text()
        go func(itemID string){
           category := api.SearchAPI.FindCategory(itemID, lang, ctx)
           _, _ = fmt.Fprintf(resp, "%v,%v \n", itemID, category)
           count++ //ENSURE YOU HAVE AN ATOMIC COUNTER INCREMENT, OR INCREMENT AFTER itemID IS READ
        }(itemID)
    }

    if err := scanner.Err(); err != nil {
        logger.Errorf("scan file error: %v", err)
        http.Error(resp, err.Error(), http.StatusBadRequest)
        return
    }

   //.....
}
resp.Header().Set("Content-Type", "text/plain")
    scanner := bufio.NewScanner(req.Body)

    ctx := context.Background()
    itemIDs := make([]string, 0)
    for scanner.Scan() {
        itemID := scanner.Text()
        itemIDs = append(itemIDs, itemID)
    }

    if err := scanner.Err(); err != nil {
        logger.Errorf("scan file error: %v", err)
        http.Error(resp, err.Error(), http.StatusBadRequest)
        return
    }

    for _, itemID := range itemIDs {
        category := api.SearchAPI.FindCategory(itemID, lang, ctx)
        _, _ = fmt.Fprintf(resp, "%v,%v \n", itemID, category)
        count++
    }

   //.....
}
Related Posts Related Posts :
  • Web Application Nat Traversal
  • Do web browsers always send a trailing slash after a domain name?
  • monitor http request from non-browser
  • What is client request?
  • Using HTTP Vary header to decide on a strategy to process a request
  • What is the HTTP_PROFILE browser header and how is it used?
  • why multipart/x-mixed-replace is needed for Comet?
  • How many threads are in Dispatchers.IO?
  • Custom HTTP headers in Razor Pages
  • Http POST request returns body as json encoded in base64
  • TidHTTPServer "Out of memory" on large file upload
  • How can I skip ssl certificate verification on HTTPS connection using the OpenEdge.Net Libraries?
  • Why are "secure" cookies insecure?
  • Is there any way that I could customize HTTP response status in Golang?
  • I want to init function in Elm
  • Cancel Http handler request
  • What are the advantages of using HTTP in Go versus using TCP Sockets for downloading/uploading files to a server?
  • Flutter - http.get fails on macos build target: Connection failed
  • How make a http post using form data in flutter?
  • HTTP verb GET or PATCH or POST or PUT when call increments views
  • cURL - how to send HTTP Request message body with GET?
  • Is there a way to use a specific TCPConn to make HTTP requests?
  • Batching technique using Protobufs
  • How to read variables found by RegEx Extractor in Debug Sampler in jMeter
  • how to clear the winsock cached http redirects (301 permanently moved)
  • slow building of long string using "+="
  • How to ask the client to downgrade a HTTP2 connection to HTTP1.1
  • Does http CONNECT method get proxy relay data at TCP level?
  • Why is it said that HTTP2 is a binary protocol?
  • Why https and www are in same URL?
  • How does QUIC connection migration actually work?
  • How to deal with large file upload via HTTP without storing the request in temporary files
  • Wireshark not showing http protocols
  • Error in the JQL Query: XXX is a reserved JQL word
  • HTTP request - Moved permanently?
  • Golang: How to copy Context object without deriving
  • How do I allow HTTP/HTTPS for GCE instances that are created using a template?
  • http.FileServer only serves index.html
  • What is the maximum number of outgoing HTTP connections a JVM app can make?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk