Problem with CefSchemeHandlerCallback at end of stream

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Problem with CefSchemeHandlerCallback at end of stream

Postby paperjam » Wed Feb 22, 2012 8:14 am

I have a CefSchemeHandler implementation that generates content programatically in its own thread. Calls usually go something like this:

Code: Select all
// This works fine...
CefSchemeHandler::ProcessRequest()
CefSchemeHandler::GetResponseHeaders()
CefSchemeHandler::ReadResponse() returning true bytes_read=0
CefSchemeHandlerCallback::BytesAvailable()
CefSchemeHandler::ReadResponse() returning true bytes_read=8192
CefSchemeHandler::ReadResponse() returning true bytes_read=32768
CefSchemeHandler::ReadResponse() returning true bytes_read=21749
CefSchemeHandler::ReadResponse() returning false
CefSchemeHandler::Cancel()


Sometimes this fails (nothing rendered) at the end of the stream. Calls look like this:

Code: Select all
// Nothing rendered, no further requests...
CefSchemeHandler::ProcessRequest()
CefSchemeHandler::GetResponseHeaders()
CefSchemeHandler::ReadResponse() returning true bytes_read=0
CefSchemeHandlerCallback::BytesAvailable()
CefSchemeHandler::ReadResponse() returning true bytes_read=423
CefSchemeHandler::ReadResponse() returning true bytes_read=0
CefSchemeHandlerCallback::BytesAvailable()
CefSchemeHandler::ReadResponse() returning false


I think this happens because my code does not know that the stream has ended when announcing the 423 bytes. I have tried using CefSchemeHandlerCallback::Cancel() at the end of stream but this seems to cancel the whole request. I can fix this by inserting dummy data at the end of the stream but this is far from ideal. Here is what the call trace looks like with a dummy byte inserted:

Code: Select all
// This works OK (but with dummy byte)...
CefSchemeHandler::ProcessRequest()
CefSchemeHandler::GetResponseHeaders()
CefSchemeHandler::ReadResponse() returning true bytes_read=0
CefSchemeHandlerCallback::BytesAvailable()
CefSchemeHandler::ReadResponse() returning true bytes_read=423
CefSchemeHandler::ReadResponse() returning true bytes_read=0
CefSchemeHandlerCallback::BytesAvailable()
CefSchemeHandler::ReadResponse() returning true bytes_read=1
CefSchemeHandler::ReadResponse() returning false
CefSchemeHandler::Cancel()


I am using cef_binary_1.963.439_windows. It looks like CefSchemeHandlerCallback::BytesAvailable() ( http://chromiumembedded.googlecode.com/ ... me_impl.cc ) should handle this situation but I have not debugged it.

Could this be a CEF problem?
paperjam
Techie
 
Posts: 21
Joined: Thu Feb 02, 2012 6:57 am

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby magreenblatt » Wed Feb 22, 2012 10:29 am

paperjam wrote:I think this happens because my code does not know that the stream has ended when announcing the 423 bytes.

What do you mean by this? Did the user cancel the request (hitting the stop button, for example)? Or do you just not want to deliver the 423 bytes that you announced were available?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby paperjam » Wed Feb 22, 2012 4:45 pm

The size of the stream is 423 bytes. I want to deliver it all and no-one has cancelled.

When 423 bytes are first available, we announce them but don't know it's the end of stream. ReadResponse delivers those 423 bytes fine. Later our thread discovers there is no more data so calls BytesAvailable to prompt a call to ReadResponse. Subsequently returning false from ReadResponse seems to lock things up.
paperjam
Techie
 
Posts: 21
Joined: Thu Feb 02, 2012 6:57 am

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby magreenblatt » Thu Feb 23, 2012 10:27 am

Please file a bug in the CEF issue tracker.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby paperjam » Fri Feb 24, 2012 8:06 am

paperjam
Techie
 
Posts: 21
Joined: Thu Feb 02, 2012 6:57 am

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby Mirco » Mon Apr 16, 2012 1:31 pm

I'm experienced a similar issue. What I'm saw was:
Code: Select all
CefSchemeHandler::ProcessRequest()
CefSchemeHandlerCallback::HeadersAvailable()
CefSchemeHandler::GetResponseHeaders()
   response_length = -1 (undetermined)
CefSchemeHandler::ReadResponse() returning true bytes_read=2
CefSchemeHandler::ReadResponse() returning true bytes_read=0
... some time later, other requests are executing ...
CefSchemeHandlerCallback::BytesAvailable()

Here I expected CefSchemeHandler::ReadResponse() being called. But ReadResponse() was never called again, leaving a hanging request.

I made the fault to save CALLBACK in ProcessRequest. Then later on when calling BytesAvailable() I was still using the saved CALLBACK. After saving the CALLBACK in ReadResponse everything works fine !
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby magreenblatt » Mon Apr 16, 2012 1:38 pm

Mirco wrote:I made the fault to save CALLBACK in ProcessRequest. Then later on when calling BytesAvailable() I was still using the saved CALLBACK. After saving the CALLBACK in ReadResponse everything works fine !

Thanks, this is indeed a problem. You must use the callback passed to the method (ProcessRequest or ReadResponse) instead of re-using the previous callback.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby Mirco » Fri May 04, 2012 12:28 pm

Hello Marshall,

I just hit this same problem, and it has nothing to do with the callback.
Code: Select all
[2012-05-04 17:46:23.451][                 352][         ][] ProcessRequest() - LocalexeRequest_1
[2012-05-04 17:46:23.481][                 636][         ][] callback->HeadersAvailable()
[2012-05-04 17:46:23.481][                 352][         ][] GetResponseHeaders()
[2012-05-04 17:46:23.481][                 352][         ][] ReadResponse() - true - 860
[2012-05-04 17:46:23.491][                 352][         ][] ReadResponse() - true - 0
[2012-05-04 17:46:23.491][                 636][         ][] callback->BytesAvailable()
[2012-05-04 17:46:23.491][                 352][         ][] ReadResponse() - false - 0
... NEVER ENDS ..., Cancel() is not called


After investigation I found a bug in scheme_impl.cc function BytesAvailable(). It looks like the ELSE branch for done notification is placed incorrectly.
Code: Select all
CEF Version: 1.963.439 --- December 22, 2011

    virtual void BytesAvailable() OVERRIDE
    {
      if (CefThread::CurrentlyOn(CefThread::IO)) {
        // Currently on IO thread.
        if (job_ && job_->has_response_started() &&
            job_->GetStatus().is_io_pending()) {
          // Read the bytes. They should be available but, if not, wait again.
          int bytes_read = 0;
          if (job_->ReadRawData(dest_, dest_size_, &bytes_read)) {
            if (bytes_read > 0) {
              // Clear the IO_PENDING status.
              job_->SetStatus(URLRequestStatus());

              // Notify about the available bytes.
              job_->NotifyReadComplete(bytes_read);

              dest_ = NULL;
              dest_size_ = 0;
            }
            //
            // MISSING ELSE, ReadRawData returns TRUE and BYTES_READ == 0 when at end of stream
            //
            else {
              job_->NotifyDone(URLRequestStatus());
            }
            //
            // END MISSING ELSE
            //
          } else {
            //
            // NOT DONE, ReadRawData returns FALSE to indicate asynchronous completion should continue using BytesAvailable
            //

            // All done.
            //job_->NotifyDone(URLRequestStatus());
          }
        }
      } else {
        // Execute this method on the IO thread.
        CefThread::PostTask(CefThread::IO, FROM_HERE,
            NewRunnableMethod(this, &Callback::BytesAvailable));
      }
    }


I hope this can be corrected !

Kind regards,
Mirco Babin
Mirco
Techie
 
Posts: 29
Joined: Mon Jun 06, 2011 1:24 pm

Re: Problem with CefSchemeHandlerCallback at end of stream

Postby magreenblatt » Fri May 04, 2012 1:01 pm

Thanks, commented in the bug report.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 45 guests