How to store a blob into a document using couchase-lite-core

@jens,

I have done that this afternoon. Check couchbase-lite-core issues.

Thanks

@jens @borrrden

I have found the culprit…

Since Jim said it didn’t had any problems running my example locally I decided to do the same. It worked.

So then I have been debugging my whole network architecture do find where the problem laid. It seems that the culprit is Traefik.

I have Traefik to allow me to expose certain urls to the network rather than access via IP address. It seems that Traefik is not handling this case very well. And it seems I’m not the only one complaining:

https://www.google.com/search?q=Error+when+copying+from+client+to+backend%3A+websocket%3A+close+1006&oq=Error+when+copying+from+client+to+backend%3A+websocket%3A+close+1006&aqs=chrome..69i57.1106j0j7&sourceid=chrome&ie=UTF-8

I’m currently using v1.7 of Traefik and using the latest version doesn’t fix the problem. I didn’t try version 2.0 because it has breaking changes and I don’t have time to learn about it right now.

In the mean time, I just wanted to confirm that the bug isn’t in couchbase-lite-core side. I will move forward with my work but I need to find a way of exposing sync-gateway url in a proper way. Any suggestions? Can you ask around inside your team if they know anything about alternatives to do this with Traefik or another kind of proxy service?

Thanks!

Best regards,

Nuno

@sinosoidal Thanks for getting back and confirming that this is not and SG issue!

I don’t know that anyone here is familiar with Traefik. I believe that most of our customers just expose the IP address and close down any unnecessary ports. If you can say more about what you mean by “exposing the url in a proper way”, I can ask around.

@blake.meike sorry if I’m using using the proper language to describe this.

Traefik is a router. Look at this docker-compose snippet to see how it works:

sync-gateway:
 build: sync-gateway
 labels:
   - traefik.backend=sg-dev
   - traefik.enable=true
   - traefik.frontend.rule=Host:sg-dev.imaginando.pt
   - traefik.frontend.entryPoints=http
   - traefik.port=4984 

With Traefik I can say any request to the url sg-dev.imaginando.pt will be forwarded to the docker service sync-gateway at port 4984. This allows me to expose only port 80. Even better is that I can than use Cloudflare to serve that url as https and have a SSL communication. This was working perfectly for documents only. For some reason, it is not working with attachments upload. The websocket is closed with the message:

Error when copying from client to backend: websocket: close 1006

Who’s fault? I don’t know. Uncharted terrain for me! The fact is that without Traefik, it works as it should be.

Maybe around your team of web developers, full stack developers, backend developers and docker wizards, someone knows alternatives to Traefik or even know about this problem that I’m having in details.

Thank you very much,

Best regards,

Nuno

Yeah… I figured that.

This is going to depend on the specifics of Traefik. In order to hold a websocket connection open, a router has to do some clever stateful trickery. I’m not surprised to hear that it fails sometimes.

Lemme ask around.

Hey @sinosoidal,
Just querying around this very forum, I see several other people mentioning Traefik in connection with similar problems.

I think you are probably just going to want to make your SG IP:port visible.

You know, btw, that CBL and the SG support SSL via the wss: URL scheme.

I’m not an easy quitter! :slight_smile:

The use of a reverse proxy such as Traefik makes configuration a breeze and solves a lot of problems.

Just to make this clear, sync-gateway replication works through Traefik for documents. Only attachments are failing. There must be something special in the attachments packets.

Are there any custom headers being transmitted so that data is validated for each transmitted packet? Maybe Traefik is not copying those headers and validation fails.

I have found this → https://docs.traefik.io/configuration/backends/docker/#custom-headers

Does this ring you any bells?

Thanks!

Best regards,

Nuno

Blob data is not much different than other data: Multi-frame messages. Perhaps this is your issue:

@blake.meike thanks for pointing this out. It’s a lead.

I need to investigate further.

Thanks!

Best regards,

Nuno