docker - ImageMagick Go API HTTP Hangs on ReadImageBlob -


i have written beego http server, when user hits endpoint:

  • the server requests image server (for instance imgur)
  • it reads bytes of image , passes them gographics/imagick
  • this (should) resize image , return byte array of result

what happens http server hangs, don't error handling, , 502 bad gateway on endpoints of server.

my code looks this:

func processcontactimage(idx int, image []byte) ([]byte, error) {     imagick.initialize()     defer imagick.terminate()     log.println("idx: ", idx)     mw := imagick.newmagickwand()      log.println("reading image blob: ", image)     err := mw.readimageblob(image)     if err != nil {         log.println("reading blob failed: ", err)         return []byte{}, err     } //... } 

i can see in terminal log message "reading image blob: [bytes, bytes bytes]" , have copied bytes printed small program test bytes indeed hold image, do. hangs on err := mw.readimageblob(image) , don't think gets if err != nil never see log message.

tips on how should debug welcome. have written small program test image magick funtions work on byte array in standalone enviroment, , works fine.

my thoughts:

  • i don't understand how go handles stack/heap, thought able move things heap if necessary , didn't need manage this. storing image in memory, thought perhaps seg fault im not sure why doesn't crash hangs...
  • readimageblob expecting type of image data, , not getting it, although have thought got error

edit:

ok comments, after more research, seems related fact running in docker, hadn't occured issue however:

  1. i have moved initialization of imagemagick main , error still occurs
  2. when run application without docker, , pass byte array handler, imagemagick code runs fine.
  3. when attach docker container, add small test program adds circle image using imagemagick (however not web service, binary) works, albeit slowly

my dockerfile looks this:

from golang:1.7-alpine  run apk update && apk add git && apk add g++ && apk add bzr && \     rm -rf /var/cache/apk/*  # env gopath /go  # install beego & bee run go github.com/astaxie/beego run go github.com/beego/bee run go github.com/tools/godep  run apk add --update alpine-sdk run apk add imagemagick-dev run go gopkg.in/gographics/imagick.v2/imagick 

i wonder if missing library or , hanging inside c api , go waiting response. there way can debug this?

ok... turns out issue else... perhaps multiple requests @ once or something... i'm not sure, have created gist demonstrating using imagemagick, in go, in handler, , works locally no problem inside docker container. mystery continues....

don't in handler:

imagick.initialize() defer imagick.terminate() 

that supposed done once, in main()

most conflicting different requests, tearing down entire imagemagick each time request finishes.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -