GithubHelp home page GithubHelp logo

gosaxon's Issues

TransformWithExecutable leaks gosaxon zombie processes inside web services

An issue has been identified when using the TransformWithExecutable function inside handler functions of web services. The XSLT transformation runs correctly but the transformer executor process is not correctly killed which results in the generation of zombie (defunct) processes. A zombie (defunct) process is generated each time the transformer runs in the web service. These processes remain in their zombie (defunct) state until the web service is restarted.

Below is an example of a web service implementation that uses the TransformWithExecutable in the handler of the /api/xslt_transform endpoint:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/chrisdutz/gosaxon/library/pkg/gosaxon"
	"github.com/gorilla/mux"
)

func main() {
	router := mux.NewRouter().StrictSlash(true)

	router.HandleFunc("/api/xslt_transform", transform).Methods("GET")

	log.Fatal(http.ListenAndServe(":8080", router))
}

func transform(w http.ResponseWriter, r *http.Request) {
	fmt.Printf("Starting Transformer")

	xml := "<fruits>\n  <apple/>\n  <pair/>\n</fruits>"
	fmt.Printf("Sending XML:\n%s\n", xml)

	xslt := "<xsl:stylesheet version=\"2.0\"\n                xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/1999/XSL/Transform\">\n    <xsl:output method=\"xml\" indent=\"yes\"/>\n\n    <xsl:template match=\"/fruits\">\n        <apples-and-friends>\n            <xsl:for-each select=\"*\">\n                <xsl:choose>\n                    <xsl:when test=\"name() = 'pair'\">\n                        <apple-like-fruit/>\n                    </xsl:when>\n                    <xsl:otherwise>\n                        <xsl:copy-of select=\".\"/>\n                    </xsl:otherwise>\n                </xsl:choose>\n            </xsl:for-each>\n        </apples-and-friends>\n    </xsl:template>\n\n</xsl:stylesheet>"
	fmt.Printf("Sending XSLT:\n%s\n", xslt)

	result, err := gosaxon.TransformWithExecutable("/tmp/gosaxon-executor.lnx", []byte(xml), []byte(xslt))
	if err != nil {
		fmt.Printf("got error: %s", err.Error())
		return
	}
	fmt.Printf("got result: \n%s", string(result))

	w.Write(result)
}

Here is an example of what the generated zombie (defunct) processes look like:

USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
user    1496  0.0  0.0      0     0 pts/0    Z+   12:07   0:00 [gosaxon-executo] <defunct>
user    1722  0.0  0.0      0     0 pts/0    Z+   12:08   0:00 [gosaxon-executo] <defunct>
user    1730  0.0  0.0      0     0 pts/0    Z+   12:08   0:00 [gosaxon-executo] <defunct>
user    1732  0.0  0.0      0     0 pts/0    Z+   12:08   0:00 [gosaxon-executo] <defunct>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.